Highlight Entire Row based on Xlookup

tedholly

New Member
Joined
Feb 19, 2021
Messages
17
Office Version
  1. 365
Platform
  1. Windows
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?

1621617993659.png
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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.
 
Upvote 0
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.
I am new to VBA so please bear with me. I am getting an error with this code.

So on Sheet 1 column N is the serial numbers that I want to match with Sheet 4 Column A. Column B on sheet 4 States which line on Sheet 1 the serial number is located. I want to highlight the row numbers on sheet 1 that match to sheet 4. (Hope this makes sense)

How can I fix this error?

1621619872624.png
 
Upvote 0
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 sheet
Excel Formula:
=MATCH(ROW(),Lookup!$B$2:$B$20,0)
 
Upvote 0
Solution
See if this is what you mean if, for some reason, you don't want to use CF.

Code:
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
 
Upvote 0
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 sheet
Excel Formula:
=MATCH(ROW(),Lookup!$B$2:$B$20,0)
This worked; thank you!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,577
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top