Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vlookup loop vba

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Vlookup loop in vba

Vlookup loop in vba

ResolvedVersion 2010

Euon has attended:
Excel Advanced course
Excel VBA Introduction course
Excel VBA Intermediate course
Excel VBA Advanced course

Vlookup loop in vba

Hi,

I am trying to make vlookups in vba work in the same way that Excel does, by looking at a range and populating a cell based on what it is looking for. The current code I have is:

Sub Caseload_Run()

Dim example As range
Set example = range("A2")

Sheets("Caseload").Select

On Error Resume Next

range("A2") = Application.WorksheetFunction.VLookup(Sheets("Lookup IDs").range("A2"), Sheets("Test Sheet").range("A3:K999999"), 1, False)

example.Offset(1, 0).Select

Do Until IsEmpty(ActiveCell.Value)
ActiveCell.Value = ActiveCell.Value
ActiveCell.Offset(1, 0).Select


End Sub


I need this to continually loop and display a figure in each cell of the "Caseload" sheet until the lookup value (Lookup IDs) in the table is blank.

I can't see a place to upload files from the computer I am using, but this would be helpful and make things easier to understand

Thanks

RE: vlookup loop in vba

Hi Euron,

Thank you for the forum question.

Yes I would like to have a look at the workbook.

Please forward it to:


info@stl-training.co.uk

Please type To Jens in the subject.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: vlookup loop in vba


Hi Euon,

Please have a look at the code below. It should do the job.


Sub LookupId()
Dim i As Integer

Sheets("Caseload").Range("A2").Select

Do Until Sheets("Lookup IDs").Cells(2 + i, 1) = ""
ActiveCell.FormulaR1C1 = _
"=VLOOKUP('Lookup IDs'!RC,'Test Sheet'!R4C1:R126341C11,1,0)"
ActiveCell.Offset(1, 0).Select
i = i + 1
Loop
End Sub





Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: vlookup loop in vba

Thanks Jens

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Quickly hide and unhide rows and columns

Use the keyboard shortcut Ctrl+9 to hide selected rows and Ctrl+0 to hide selected columns. The good thing about this shortcut is that you do not need to select entire rows or columns. For example, select B3:D3 then press Ctrl+0 to hide columns B to D.

Ctrl+Shift+9 unhides rows and Ctrl+Shift+0 unhides columns.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.