vlookup loop vba

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

Vlookup loop in vba

resolvedResolved · High Priority · Version 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:

Repeating headings on spreadsheets that print on more than one page

By default when you print a spreadsheet out and it prints on more than one page, the headings at the top and the side of the spreadsheet don't appear on all the pages following page 1.

To get Excel to repeat headings on all pages when printing, go to File - Page Setup - Sheet, then select the rows to repeat at the top of pages, and the columns to repeat at the side of pages by clicking on the red arrows at the right side of the two boxes under the 'Print titles' area. Then click OK.

If you view your spreadsheet in Print Preview, you should see the headings being repeated on each page.

View all Excel hints and tips


Server loaded in 0.06 secs.