Link to home
Start Free TrialLog in
Avatar of Seamus2626
Seamus2626Flag for Ireland

asked on

Change Column Ref

Hi,

I have a sub below.

Instead of highlighting as far as Col G, i would like it to find the Column which has ("Grand Total in Row 4 and only highlight as far as that

Thanks
Seamus



Sub ASPASOPHISHKMATCH()
Dim wkb As Workbook
Dim wksA As Worksheet
Dim wksB As Worksheet
Dim rng As Range
Dim r As Range
Dim rFind As Range
Dim rColor As Range

    Set wkb = ThisWorkbook
    Set wksA = wkb.Sheets("ASPA HK")
    Set wksB = wkb.Sheets("Sophis HK Pivot")
   
    Set rng = wksA.Range("A5", wksA.Range("A" & Rows.Count).End(xlUp).Offset(-1, 0))
   
    For Each r In rng
        Set rColor = wksA.Range(r, wksA.Cells(r.Row, "G"))
        Set rFind = wksB.Range("A:A").Find(what:=r.value, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext)
        If Not rFind Is Nothing Then
            rColor.Interior.Color = vbGreen
        Else
            rColor.Interior.Color = vbRed
        End If
    Next r
   
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Ingeborg Hawighorst (Microsoft MVP / EE MVE)
Ingeborg Hawighorst (Microsoft MVP / EE MVE)
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not for points:

I would do this bit:
WorksheetFunction.Match("Grand Total", wksA.Range("4:4"), 0)

Open in new window


outside the loop as it doesn't change.
Avatar of Seamus2626

ASKER

Thanks Teylyn,

Thank you too Rory

Seamus