将 VBA 代码应用于更多行或行范围

发布于 2025-01-11 03:06:39 字数 332 浏览 0 评论 0原文

我只是想应用仅在行中工作的方法。

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("P6:R6")) Is Nothing Then Exit Sub
Cells(O6, O15).Select

End Sub

目标:单击要重定向到某个单元格的特定单元格(我将保护除目标单元格之外的这些单元格。)我希望它仅适用于特定范围的行,但不连续。我希望应用此代码的行之间会有间隙。

到目前为止我找到的步骤:上面的公式是我在网上找到的,仅适用于 1 行。

I am just trying to apply that is working in row only.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("P6:R6")) Is Nothing Then Exit Sub
Cells(O6, O15).Select

End Sub

Goal: Click specific cells to be redirected to a cell( I will protect those cells except for the target cell.) I want it to work to specific range of rows only but not continuous. There will be gaps between rows I want this code to apply.

Steps I Found So Far: The formula above I found online and that only works in 1 row.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回旧景 2025-01-18 03:06:39

试试这个:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Target.Cells.CountLarge > 1 Then Exit Sub 'single-cell selections only
    
    If Not Intersect(Target, Me.Range("P6:R100")) Is Nothing Then
        'Do not need to disable events before selecting, since we're not
        '   selecting a range in the monitored region 
        Me.Cells(Target.Row, "O").Resize(10).Select
    End If

End Sub

Try this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Target.Cells.CountLarge > 1 Then Exit Sub 'single-cell selections only
    
    If Not Intersect(Target, Me.Range("P6:R100")) Is Nothing Then
        'Do not need to disable events before selecting, since we're not
        '   selecting a range in the monitored region 
        Me.Cells(Target.Row, "O").Resize(10).Select
    End If

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文