gpt4 book ai didi

excel - 如何循环函数 VBA Excel

转载 作者:行者123 更新时间:2023-12-04 21:46:32 27 4
gpt4 key购买 nike

我想将此代码应用于单元格(P2 到 P300),但我不知道如何编写它。

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("P2")) Is Nothing Then
Dim Fl2 As String
Fl2 = Range("O2")
Call Shell("explorer.exe /select," & Fl2, vbNormalFocus)
End If

If Not Intersect(Target, Range("P3")) Is Nothing Then
Dim Fl3 As String
Fl3 = Range("O3")
Call Shell("explorer.exe /select," & Fl3, vbNormalFocus)
End If
如何获得更简单的方法?

最佳答案

使用 Intersect 进行了一些清理在整个范围和 Offset引用 O 列中的相应单元格。

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

If Not Intersect(Target, Me.Range("P2:P200")) Is Nothing Then
Shell "explorer.exe /select," & Target.Offset(,-1).Value, vbNormalFocus
End If

End Sub

关于excel - 如何循环函数 VBA Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64056531/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com