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
VLookup
Resolved · Urgent Priority · Version 2010
Freddie has attended:
Excel VBA Introduction course
VLookup
Hi Guys
Thanks for your responses on my other questions, I have one more query though. I'm looking to perform a basic Vlookup, but my code keeps on falling over?
All I'm looking to do is just look up a prior cell's value in another worksheet?
Sheets("LBAPARIF").Select
Range("L2").Select
Do Until ActiveCell.Offset(0, -1) = ""
ActiveCell.Value = Application.WorksheetFunction.VLookup(Range("Activecell.Offset(0,-1"), _
Worksheets("LBARATEF").Range("E2:f523"), 2, 0)
ActiveCell.Offset(1, 0).Select
Loop
Any help is greatly appreciated!
Thanks!
Freddie
RE: VLookup
Hi Freddie,
Thank you for the forum question.
What you want you can record with the macro recorder. Start the recorder and do what you want and you will have the code in the visual basic editor. Just record it for the first record and put it inside the loop.
I did it with one of my workbooks and got this:
Sheets("lists").Select
Range("A5").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[1],lists2!R3C2:R22C2,1,0)"
and then I added the loop and ended like this:
Sub Macro1()
Sheets("lists").Select
Range("A5").Select
Do Until ActiveCell.Offset(0, -1) = ""
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[1],lists2!R3C2:R22C2,1,0)"
ActiveCell.Offset(1, 0).Select
Loop
End Sub
I hope that this can help you.
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
Hi Freddie,
Thank you for your question.
Please have a look at the following code where I've made some changes. I've streamlined it but more importantly, I would suggest giving your data table on the LBARATEF sheet a range name. This helps to tidy up your code. In my example I used "rangename" (see below). Also, in your vlookup formula there is a speechmark in the offset brackets, which you need to delete.
Sheets("LBAPARIF").Range("L2").Select
Do Until ActiveCell.Offset(0, -1) = ""
ActiveCell = WorksheetFunction.VLookup(Activecell.Offset(0,-1), _
Range("rangename"), 2, 0)
ActiveCell.Offset(1, 0).Select
Loop
I hope this helps.
Kind regards
Marius Barnard
Excel Trainer
RE: VLookup
Hi Guys
Any response to the above? I can't understand why the vlookup isn't being performed? Is it a question of formatting perhaps?
Please advise.
Thanks!
Freddie
RE: VLookup
Hi Freddie,
Is it possible to forward the workbook to me because I am not sure that I can help you without having a look at the file. Normally when we get problems with lookup functions it is because the data need to be cleaned. I do not know if this is the issue but it could be.
You can forward the file to:
info@stl-training.co.uk
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
Hi Guys
Thanks for the above. I just have one issue though still. For the majority of data, the vlookup works, however there are some results that have just returned the following:
=VLOOKUP(RC[-1],LBARATEF!C[-7]:C[-6],2,0)
Can you please advise as to why? How can I rectify this?
Thanks for all your help!
Freddie
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:Navigate with keyboard without losing your active cellIf you like using your keyboard to scroll through your excel document, but want to keep your active cell the same, use the scroll lock, and then use your arrow keys to navigate around the document. |