I have this amazing code, but it highlights all coolumns in sheet. Any way to get this vba code to only highlight columns A and B?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const RefClm As Long = 1 ' specified column B
' change as appropriate
Dim Rng As Range
Dim RefRng As Range
Dim Fnd As Range, Rf As Long
Dim Ref As Variant
Dim Cl As Long ' Last used column in row 1
Dim R As Long
Cl = Cells(1, Columns.Count).End(xlToLeft).Column
Set Rng = Range(Cells(2, 1), Cells(Cells(Rows.Count, RefClm).End(xlUp).Row, Cl))
Set Target = Target.Cells(1)
If Not Application.Intersect(Target, Rng) Is Nothing Then
Ref = Cells(Target.Row, RefClm).Value
Rng.Interior.Pattern = xlNone
Set RefRng = Rng.Columns(RefClm)
With RefRng
' Find method: https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2003/aa195730(v=office.11)
Set Fnd = .Find(What:=Ref, After:=.Cells(.Cells.Count), LookAt:=xlWhole)
End With
Rf = Fnd.Row
Set Target = Range(Cells(Rf, 1), Cells(Rf, Cl))
Do
Set Fnd = RefRng.FindNext(After:=Fnd)
If (Fnd Is Nothing) Or (Fnd.Row = Rf) Then
Exit Do
Else
Set Target = Union(Target, Range(Cells(Fnd.Row, 1), Cells(Fnd.Row, Cl)))
End If
Loop
Target.Interior.Color = vbYellow
End If
End Sub