Vlookup code not working

Newbie74

New Member
Joined
Feb 6, 2014
Messages
10
Hi,

I have the following code which is working, however I need to keep running the Macro for each line for it to work properly. When I put it into a Do Until Loop I get an error on every line (I've added my code that I am typing for the loop as a comment on the code below). How can I knock this out into a do until loop without getting errors on each line?

Sub LookingUp()


Dim Luk As String
Dim Sal As Variant


Luk = ActiveCell.Offset(0, -2)




'Do Until ActiveCell.Offset(0, -2) = ""


On Error Resume Next


Sal = Application.WorksheetFunction.VLookup(Luk, Sheets("Sheet1").Range("E:F"), 2, False)


If Err.Number = 0 Then
ActiveCell.Value = Sal


Else
ActiveCell = "Error"
End If


ActiveCell.Offset(1, 0).Select


'Loop
End Sub
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Welcome to the board.

You have to update the value of Luk within the loop.

You gave it a value on the first line
Luk = ActiveCell.Offset(0, -2)

However, the value of Luk does NOT update as the ActiveCell changes while you're running the loop.
 
Last edited:

Newbie74

New Member
Joined
Feb 6, 2014
Messages
10
Hi Jonmo1, Thanks for your speed response!

I don't understand what you mean by the value of Luk not updating. How should the code look like as I did try Do until activecell.offset(0,-1) and it still did not work.
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Put
Luk = ActiveCell.Offset(0, -2)

AFTER the line that starts the loop

Code:
Do Until ActiveCell.Offset(0, -2) = ""
    Luk = Activecell.Offset(0, 2)

    Do stuff...

Loop
 

Watch MrExcel Video

Forum statistics

Threads
1,127,925
Messages
5,627,667
Members
416,263
Latest member
Doblez

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
Top