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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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