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..


[TABLE="width: 323"]
<colgroup><col><col><col><col><col></colgroup><tbody>[TR]
[TD]cake[/TD]
[TD="align: right"]0.75[/TD]
[TD][/TD]
[TD][/TD]
[TD]tea[/TD]
[/TR]
[TR]
[TD]chips[/TD]
[TD="align: right"]1.20[/TD]
[TD][/TD]
[TD][/TD]
[TD]sandwich[/TD]
[/TR]
[TR]
[TD]chocolate[/TD]
[TD="align: right"]0.55[/TD]
[TD][/TD]
[TD][/TD]
[TD]pizza[/TD]
[/TR]
[TR]
[TD]crisp[/TD]
[TD="align: right"]0.70[/TD]
[TD][/TD]
[TD][/TD]
[TD]pastie[/TD]
[/TR]
[TR]
[TD]curry[/TD]
[TD="align: right"]2.50[/TD]
[TD][/TD]
[TD][/TD]
[TD]drink[/TD]
[/TR]
[TR]
[TD]drink[/TD]
[TD="align: right"]0.50[/TD]
[TD][/TD]
[TD][/TD]
[TD]curry[/TD]
[/TR]
[TR]
[TD]pastie[/TD]
[TD="align: right"]1.30[/TD]
[TD][/TD]
[TD][/TD]
[TD]crisp[/TD]
[/TR]
[TR]
[TD]pizza[/TD]
[TD="align: right"]1.50[/TD]
[TD][/TD]
[TD][/TD]
[TD]chocolate[/TD]
[/TR]
[TR]
[TD]sandwich[/TD]
[TD="align: right"]1.99[/TD]
[TD][/TD]
[TD][/TD]
[TD]chips[/TD]
[/TR]
[TR]
[TD]tea[/TD]
[TD="align: right"]0.75[/TD]
[TD][/TD]
[TD][/TD]
[TD]cake[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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