Highlight Key Items

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
hello all

I have this script which functions as expected, what I'd like accomplish prior to replacing the applicable values is highlight the values. unsure maybe stop at this point or continue to the replacement.

Thanks as always

Code:
Sub HighlightValues()   
   Dim c As Range
   Dim k As Variant
   Dim Ws1 As Worksheet, Ws2 As Worksheet
   
   Set Ws1 = Sheets("Sheet1")
   Set Ws2 = Sheets("Sheet2")
   With CreateObject("scripting.dictionary")
      For Each c In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
         .Item(c.Value) = c.Offset(, 1).Value
      Next c
      
      For Each k In .Keys
[COLOR=#ff0000]      'Highlight items at this point[/COLOR]
      Ws1.UsedRange.Replace k, .Item(k), xlWhole, , True, , False, False
      Next k
   End With
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
.
Untested here.

Code:
For Each k In .Keys
      'Highlight items at this point
      k.Interior.Color = vbYellow
      Ws1.UsedRange.Replace k, .Item(k), xlWhole, , True, , False, False
      Next k
End Sub

Not certain using the "k" variable as the target is going to work. I'm thinking using the "c" variable would be correct and that would be (I believe without testing here)

Code:
 With CreateObject("scripting.dictionary")
      For Each c In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
         .Item(c.Value) = c.Offset(, 1).Value
         .Interior.Color = vbYellow
      Next c
 
Last edited:
Upvote 0
Thank you. I actually attempted to highlight on the k prior. That did not work. I'll test the second option provided and update.
 
Last edited:
Upvote 0
Unfortunately this change does not work. I am trying to highlight the values which are to be replaced on Sheet1
 
Upvote 0
Hi, billandrew
This is also untested
Note: I changed the second parameter to "", means Replacement:=""
& the last parameter from False to True, means 'ReplaceFormat:=True'

Code:
      For Each k In .Keys
      'Highlight items at this point
      Application.ReplaceFormat.Interior.Color = vbYellow
      ws1.UsedRange.Replace k, "", xlWhole, , True, , False, True
      Next k
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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