I have an xlookup that matches my column A Serial number to a master data sheet. The Xlookup tells me which row the value is located in. How can I highlight the entire row of the corresponding Serial Number in the Master Data tab?
Sub TedHolly()
Dim r As Long, lr As Long
lr = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row
r = WorksheetFunction.Match(Cells(2, "K"), Sheets("Master").Range("A1:A" & lr), 0) ' change Cells(2, "K") to where the Serial # is located
Sheets("Master").Range("A" & r & ":H" & r).Interior.ColorIndex = 6 ' for example: yellow; change value for different color; change "H" for different end of range or set to extent of columns
End Sub
I am new to VBA so please bear with me. I am getting an error with this code.What about:
Code:Sub TedHolly() Dim r As Long, lr As Long lr = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row r = WorksheetFunction.Match(Cells(2, "K"), Sheets("Master").Range("A1:A" & lr), 0) ' change Cells(2, "K") to where the Serial # is located Sheets("Master").Range("A" & r & ":H" & r).Interior.ColorIndex = 6 ' for example: yellow; change value for different color; change "H" for different end of range or set to extent of columns End Sub
This doesn't provide for an error if the S# isn't found.
=MATCH(ROW(),Lookup!$B$2:$B$20,0)
Sub TedHolly()
Dim r As Long, lrm As Long, lr1 As Long, i As Long, c As Long, cl As Variant
lrm = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row ' number of rows in master
lr1 = Sheets("Sheet1").Cells(Rows.Count, "N").End(xlUp).Row ' number of rows w/S#
c = Sheets("Master").UsedRange.Columns.Count
For i = 1 To lr1
r = WorksheetFunction.Match(Cells(i, "N"), Sheets("Master").Range("A1:A" & lrm), 0)
cl = Cells(r, c).Address
Sheets("Master").Range("A" & r & ":" & cl).Interior.ColorIndex = 6 ' for example: yellow
Next i
End Sub
This worked; thank you!You can also use conditional formatting for this.
Select the relevant cells on the master sheet (say A1:Z100) and use this formula in conditional formatting on that sheetExcel Formula:=MATCH(ROW(),Lookup!$B$2:$B$20,0)