Finding matching values

Nanditha

New Member
Joined
May 28, 2021
Messages
10
Office Version
  1. 2013
Platform
  1. Windows
Hi friends… I am looking at your expertise in the below.
I have 2 excel worksheets (dnd and cc5). I have a set of values (text) in column A. I need to highlight the matching values between sheet dnd (column A) and cc5 (column P) in green text in column P.
I used the below command but it only finds the values which is in A4. Rest of the row values are not getting highlighted.

Sheets(“dnd”).Select
Range(“A3”).Select

For Each cell in Test.columns(“A”).cells.specialcells(xlcelltypevisible)

selection.offset(1,0).select
Sheets(“cc5”).select
Cells.find(what:=sheets(“dnd”).range(“A4”),searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate

can someone help me to correct the code which is match all values in column A with cc5 sheet column P.
Thanks a lot for your help!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi & welcome to MrExcel.
You can do that with conditional formatting.
Select P2 to last row in P & then in conditional formatting, new rule, use a formula & use
Excel Formula:
=MATCH(P2,dnd!$A$2:$A$1000,0)
then set the format you want.
 
Upvote 0
Thank you for the response. But i need this as 1 part of the macro i am working on.
 
Upvote 0
Ok, how about
VBA Code:
Sub Nanditha()
   Dim Cl As Range
   Dim Dic As Object
   
   Set Dic = CreateObject("scripting.dictionary")
   Dic.CompareMode = 1
   With Sheets("dnd")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         Dic(Cl.Value) = Empty
      Next Cl
   End With
   With Sheets("cc5")
      For Each Cl In .Range("P2", .Range("P" & Rows.Count).End(xlUp))
         If Dic.Exists(Cl.Value) Then Cl.Font.Color = rgbLimeGreen
      Next Cl
   End With
End Sub
 
Upvote 0
Solution
This was awesome. But one problem.
The moment i defined Cl As Range. It says Cl = Nothing

so the following codes are not executed.
 
Upvote 0
I'm afraid I don't understand what you mean, Cl is already defined as range
 
Upvote 0
I'm afraid I don't understand what you mean, Cl is already defined as range
Apologies for being unclear.. may be the attached picture might help!
 

Attachments

  • 6FD25410-0DC8-4FCC-99C0-FC06C21B8D26.jpeg
    6FD25410-0DC8-4FCC-99C0-FC06C21B8D26.jpeg
    44.3 KB · Views: 18
Upvote 0
That is because Cl is Nothing at that point in the code, it only becomes something on the next line.
 
Upvote 0
But the macro doesn’t run to the next line. It gives me Run-time error ‘424’: Object required
That is because Cl is Nothing at that point in the code, it only becomes something on the next line.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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