Search for Match and Return Value on 2 lists

fatnhappy

Board Regular
Joined
Nov 8, 2003
Messages
132
Hello.....

I have code that works well to use a value in each row in a column in WS1 and compare it to a list of names in WS2 and if there is a match, put the value in WS2 A1 into Cell O of WS1 (offset 11 columns). What I want to do is make this an "OR" and compare to WS2 range A2:A14 OR WS2 C2:C26. If there was a match in the range in column A it would return the value in A1 and if there was a match to the range in Column C it would return the value in C1.

Thanks for any help....

Code:
Sub Find_Category()


   Dim Cl As Range, c2 As Range
   Dim Ws1 As Worksheet, Ws2 As Worksheet
   
   Set Ws1 = Sheets("FG Report")
   Set Ws2 = Sheets("Posting Names")
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws2.Range("A2:A14")
         .Item(Cl.Value) = Ws2.Range("A1").Value
         
      Next Cl
      For Each Cl In Ws1.Range("D3", Ws1.Range("D" & Rows.Count).End(xlUp))
         Cl.Offset(, 11).Value = .Item(Cl.Value)
      Next Cl
   End With

   End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try
Code:
Sub Find_Category()
   Dim Cl As Range
   Dim Ws1 As Worksheet, Ws2 As Worksheet
   
   Set Ws1 = Sheets("FG Report")
   Set Ws2 = Sheets("Posting Names")
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws2.Range("A2:A14")
         .Item(Cl.Value) = Ws2.Range("A1").Value
      Next Cl
      For Each Cl In Ws2.Range("C2:C26")
         .Item(Cl.Value) = Ws2.Range("C1").Value
      Next Cl
      For Each Cl In Ws1.Range("D3", Ws1.Range("D" & Rows.Count).End(xlUp))
         Cl.Offset(, 11).Value = .Item(Cl.Value)
      Next Cl
   End With

   End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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