Highlight numerous referenced cells through Loop

heifer624

New Member
Joined
Apr 30, 2012
Messages
46
I have the need to highlight about 20K+ cells in one worksheet with cells referenced in another worksheet. Need a VBA loop solution for this. As example:
Have a sheet named "GoBaby" in which the cells need highlighting if they match the cell values referenced in sheet named "Matched" . So Matched A1 value is P3 so I need P3 on GoBaby highlighted. Then Matched A2 value is Z8 so I need Z8 on GoBaby highlighted. Then Matched A3 value is X18 so I need X18 on GoBaby highlighted. etc, etc.

Thanks in advance
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Perhaps:
Code:
Dim cel As Range
On Error Resume Next
For Each cel In Sheets("Matched").UsedRange
    Sheets("GoBaby").Range(cel).Interior.Color = vbYellow
Next
 
Upvote 0
Could you use standard Conditional Formatting? (Not sure how it will go with such a big range but you could give it a go)

If all the addresses are listed in column A of 'Matched' (can adapt if multiple columns are used on 'Matched') then would this work for you?
1. On 'GoBaby' select fthe whole range that could possibly be involved.
2. Home ribbon tab -> Conditional Formatting -> New rule .. -> Use a formula to determine which cells to format -> Format values where this formula is true: =MATCH(ADDRESS(ROW(),COLUMN(),4),Matched!$A:$A,0) -> Format... -> Choose your format -> OK -> OK
 
Upvote 0
For a macro solution, maybe something like this...
Code:
[table="width: 500"]
[tr]
	[td]Sub ColorMatchedCells()
  Dim Cell As Range
  Application.ReplaceFormat.Clear
  Application.ReplaceFormat.Interior.Color = vbYellow
  For Each Cell In Sheets("Matched").UsedRange
    If Len(Cell.Value) Then Sheets("GoBaby").UsedRange.Replace Cell.Value, "", xlWhole, , False, , False, True
  Next
  Application.ReplaceFormat.Clear
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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