in the below code, if I select cell B* or cell C* , It subsequently selects range B*:G* on the same row. please, How to include non-contiguous cell (E) in Const cFirstRow As String = "B3:C3" .I tried "B3:C3,E3" but it gives me an error "Run-time error '1004': Method 'Range' of object '_Worksheet' failed.
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const cFirstRow As String = "B3:C3"
Const sCols As String = "B:G"
Dim crg As Range
With Range(cFirstRow)
Set crg = .Resize(Rows.Count - .Row + 1)
End With
Dim irg As Range: Set irg = Intersect(crg, Target)
If Not irg Is Nothing Then
Dim srg As Range, arg As Range, rrg As Range
For Each arg In irg.Areas
For Each rrg In arg.Rows
If srg Is Nothing Then
Set srg = Columns(sCols).Rows(rrg.Row)
Else
Set srg = Union(srg, Columns(sCols).Rows(rrg.Row))
End If
Next rrg
Next arg
If Not srg Is Nothing Then
srg.Select
End If
End If
End Sub
