1

I want to apply this code to Cells (P2 to P300) but i don't know how to write it.

    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

How to get more easy way?

2 Answers 2

2

Cleaned up a bit using Intersect on the entire range and Offset to refer to the corresponding cell in column 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
Sign up to request clarification or add additional context in comments.

Comments

1

The Insersect statement accepts multi-cell range

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.