98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Vlookup loop in vba
Vlookup loop in vba
Resolved · 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
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
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 pageBy 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. |