Coping Formula to LastRow

MM91

Board Regular
Joined
Nov 29, 2021
Messages
59
Office Version
  1. 365
Platform
  1. Windows
Hi I am trying to include a macro that will copy formulas down until the last row of data but it keeps giving me a compile error:Expected end of statement.
The first is trying to copy a vlookup formula, the second line is trying to copy a simple row number

Thanks!

Sub CopyFormulas()

Range("G7:G" & LastRow).Formula = "=IFERROR(VLOOKUP(TEXT(G7,0),'N:\X:\Purchase_Part_Library\[BOM NAV Item List.xlsx]Sheet1'!$A$8:$I$1000000,5,FALSE),"N/A")"
Range("Q7:Q" & LastRow).Formula = "=ROW()-6"


End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
It is because the " in your formula are being identified as VBA text qualifiers.

Try changing this line:
Excel Formula:
Range("G7:G" & LastRow).Formula = "=IFERROR(VLOOKUP(TEXT(G7,0),'N:\X:\Purchase_Part_Library\[BOM NAV Item List.xlsx]Sheet1'!$A$8:$I$1000000,5,FALSE),"N/A")"
to this:
Excel Formula:
Range("G7:G" & LastRow).Formula = "=IFERROR(VLOOKUP(TEXT(G7,0),'N:\X:\Purchase_Part_Library\[BOM NAV Item List.xlsx]Sheet1'!$A$8:$I$1000000,5,FALSE),""N/A"")"

Also, I can only assume that you have defined LastRow as a global variable and populated its values elsewhere, because it is not in the code.
 
Upvote 0
Solution
Awesome I didn't have it defined as a global variable. Also the addition of the quote symbols fixed the compiling error. Thank you I really appreciate the help!!
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,525
Members
448,969
Latest member
mirek8991

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