Writing Vlookups in VBA

Godders199

Active Member
Joined
Mar 2, 2017
Messages
313
Office Version
  1. 2013
Hello, I am always recording and adding vlookup into Marco's as below, I will like to understand how to write it within vba rather than recording everything, also if possible how only to put the result in the cell , rather than the formula.

the basic formula is

=IFERROR(VLOOKUP(AB2,'SQ Hierarchy'!A:C,3,FALSE),"")

My current code when i add to by vba is

Dim LR1 As Long
LR1 = Range("a" & Rows.Count).End(xlUp).Row
Range(“z2”).select
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC[2],'SQ Hierarchy'!C[-25]:C[-23],3,FALSE),"""")"
Range("Z3").Select
Range("z2").Copy
Range("z3:z" & LR1).PasteSpecial xlPasteAll
Application.CutCopyMode = False


This is just one example, of the 10 I need to add in, I am just looking to progress my knowledge and make my VBA look more professional

I have tried working through some examples i have found online but they never seem to work when adapting to my worksheets.

Any help would be appreciated
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top