Lookup Values

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
How would I change this code to work in a slightly different way. I have a value in Sheet1("A4") and I want to lookup this value on Sheet2("A1:F20") with the value being in column F. I then want to put the corresponding value from Column A in Sheet1("A6"), the next corresponding value in Sheet1("A16"), the next on Sheet1("A26"). I would also like to count how many times the value show up in Column F and put that number in Sheet1("B4"). Hope that makes sense. thanks!



Sub helpexcel()
Dim Ws1 As Worksheet, Ws2 As Worksheet
Dim Cl As Range

Set Ws1 = ThisWorkbook.Sheets("Sheet3")
Set Ws2 =Workbooks("Data").Sheets("Sheet1")
Application.ScreenUpdating = False
With CreateObject("scripting.dictionary")
.CompareMode = 1
For Each Cl In Ws2.Range("A5", Ws2.Range("A" & Rows.Count).End(xlUp))
.Item(Cl.Value) = Cl.Offset(, 22).Value
Next Cl
For Each Cl In Ws1.Range("A2", Ws1.Range("A" & Rows.Count).End(xlUp))
Cl.Offset(, 12).Value = IIf(LCase(.Item(Cl.Value)) = "empty", "Sold out", .Item(Cl.Value))
Next Cl
End With
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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