Vlookup autofill

afc171

Board Regular
Joined
Jan 14, 2017
Messages
143
Office Version
  1. 2013
Platform
  1. Windows
Hi guys,

I am trying to create a macro button which would autofill a vlookup code into a column

VBA Code:
Dim lastrow As Long
lastrow = Range("A2").End(xlDown).Row

Range("B2:B" & lastrow).FormulaR1C1 = "=VLOOKUP(B2&,'Stk_Qty-LC'!A:F,5,FALSE)"

Columns("H:I").EntireColumn.AutoFit

Keeps giving me run-time error 1004 object range failed?!
Is there an easier way to do this?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You are using FormulaR1C1, but then using a vlookup that has A1 notation instead. Either use Formula, or change the vlookup to use R1C1 notation.
 
Upvote 0
Just noticed, you also have an & after the cell reference in the formula, you will need to remove it.
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,871
Members
449,097
Latest member
dbomb1414

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