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