vba code for vlook loop

Johnsmith999

New Member
Joined
Dec 27, 2018
Messages
3
Hi,

I want to set up a simple vlu loop to copy data from one sheet to another

and I want the loop to end when when the loop reaches the end of the list.

let's assume the list of items with prices (columns 1&2) is on sheet 1 and the vlu required (column 3) is on sheet 2

Its early days for me, I am trying to teach myself using utube videos etc. but can't seem to grasp the idea of variables and how they interact with do until, do while, next, etc.

Please help..


cake0.75tea
chips1.20sandwich
chocolate0.55pizza
crisp0.70pastie
curry2.50drink
drink0.50curry
pastie1.30crisp
pizza1.50chocolate
sandwich1.99chips
tea0.75cake

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi and welcome to MrExcel.
This assumes that you have headers in row 1, with data starting in row2.
Code:
Sub JohnSmith999()
   Dim Ary As Variant
   Dim i As Long
   
   Ary = Sheets("Sheet2").Range("A1").CurrentRegion.Value2
   With CreateObject("scripting.dictionary")
      .CompareMode = 1
      For i = 2 To UBound(Ary)
         .Item(Ary(i, 1)) = Ary(i, 2)
      Next i
      Ary = Sheets("sheet1").Range("A1").CurrentRegion.Value2
      For i = 2 To UBound(Ary)
         Ary(i, 3) = .Item(Ary(i, 1))
      Next i
   End With
   Sheets("sheet1").Range("A1").Resize(UBound(Ary), UBound(Ary, 2)).Value = Ary
End Sub
 
Upvote 0
With data on sheet1 like

Excel 2013/2016
AB
1PcodePrice
2AL1 5EG147
3AL10 9WX13
4AL2 1UX6
5AL2 2EJ19
6AL2 2EX12
7AL2 3XZ15
8AL2 3YT23
9AL3 6AD22
10AL3 6NZ5
Sheet1

And on sheet 2 like

Excel 2013/2016
AB
1PcodeWard
2AL1 5EGHatfield South West
3AL10 9WXLondon Colney
4AL2 1UXAldenham West
5AL2 2EJSopwell
6AL2 2EXPark Street
7AL2 3XZSt Stephen
8AL2 3YTVerulam
9AL3 6ADBatchwood
10AL3 6NZCunningham
Sheet2


Do you want

Excel 2013/2016
ABC
1PcodePriceWard
2AL1 5EG147Hatfield South West
3AL10 9WX13London Colney
4AL2 1UX6Aldenham West
5AL2 2EJ19Sopwell
6AL2 2EX12Park Street
7AL2 3XZ15St Stephen
8AL2 3YT23Verulam
9AL3 6AD22Batchwood
10AL3 6NZ5Cunningham
Sheet1
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,184
Members
448,554
Latest member
Gleisner2

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