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
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
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:
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,447
Members
448,898
Latest member
drewmorgan128

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