Lookup Data in Sheet1 on Sheet2 or Sheet3 and Return Value

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi - How do I lookup an item on 2 lists with out the ws3 overriding the ws2 inputs? basically changing it so that if it cant find the item from ws1 in ws2, then look in ws3. This is the code I tried to modify to add ws3. thanks!
Code:
[COLOR=#333333]With CreateObject("scripting.dictionary") [/COLOR]
[COLOR=#333333].CompareMode = 1[/COLOR]
[COLOR=#333333]For Each Cl In ws2.Range("E45", ws2.Range("E" & Rows.Count).End(xlUp))[/COLOR]
[COLOR=#333333].Item(Cl.Value) = Cl.Offset(, 2).Value[/COLOR]
[COLOR=#333333]Next Cl[/COLOR]
[COLOR=#333333]For Each Cl In ws1.Range("A11", ws1.Range("A" & Rows.Count).End(xlUp))[/COLOR]
[COLOR=#333333]Cl.Offset(, 1).Value = .Item(Cl.Value)[/COLOR]
[COLOR=#333333]Next Cl[/COLOR]
[COLOR=#333333]For Each Cl In ws3.Range("E45", ws3.Range("E" & Rows.Count).End(xlUp))[/COLOR]
[COLOR=#333333].Item(Cl.Value) = Cl.Offset(, 2).Value[/COLOR]
[COLOR=#333333]Next Cl[/COLOR]
[COLOR=#333333]For Each Cl In ws1.Range("A11", ws1.Range("A" & Rows.Count).End(xlUp))[/COLOR]
[COLOR=#333333]Cl.Offset(, 1).Value = .Item(Cl.Value)[/COLOR]
[COLOR=#333333]Next Cl[/COLOR]
[COLOR=#333333]End With[/COLOR]
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Ok, can you please explain, in words, what you are trying to do for the next part. Also when referring to columns please use the column letters, not numbers.
 
Upvote 0
I figured it out. If I use the Create Object before each block of code it works great.
Code:
With CreateObject("scripting.dictionary")     
 .CompareMode = 1
        For Each Cl In ws2.Range("E45", ws2.Range("E" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Cl.Offset(, 2).Value
        Next Cl
        For Each Cl In ws3.Range("E45", ws3.Range("E" & Rows.Count).End(xlUp))
        If Not .Exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, 2).Value
        Next Cl
        For Each Cl In ws1.Range("A11", ws1.Range("A" & Rows.Count).End(xlUp))
         Cl.Offset(, 1).Value = .Item(Cl.Value)
         Next Cl
    End With
 
    With CreateObject("scripting.dictionary")
      .CompareMode = 1
        For Each Cl In ws2.Range("E45", ws2.Range("E" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Cl.Offset(, 15).Value
        Next Cl
        For Each Cl In ws3.Range("E45", ws3.Range("E" & Rows.Count).End(xlUp))
        If Not .Exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, 15).Value
        Next Cl
        For Each Cl In ws1.Range("A11", ws1.Range("A" & Rows.Count).End(xlUp))
         Cl.Offset(, 12).Value = .Item(Cl.Value)
        Next Cl
    End With
 
Last edited:
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,825
Members
449,190
Latest member
rscraig11

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