Using VBA to insert formulas

no_Fate

New Member
Joined
Jan 22, 2015
Messages
6
Hi all,

I'm trying to use VBA to insert the formula below into a cell but I always get a runtime error 1004.

Code:
Sub Fill_Formulas()
     
    ThisWorkbook.Worksheets(4).Range("D2").Formula = "=IFERROR(VLOOKUP($A$2;'[Daily Tracker.xlsx]Info'!$A:$I;2;FALSE);"")"
    
End Sub

What am I doing wrong?
Thank you in advance!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi all,

I'm trying to use VBA to insert the formula below into a cell but I always get a runtime error 1004.

Code:
Sub Fill_Formulas()
     
    ThisWorkbook.Worksheets(4).Range("D2").Formula = "=IFERROR(VLOOKUP($A$2;'[Daily Tracker.xlsx]Info'!$A:$I;2;FALSE);"")"
    
End Sub

What am I doing wrong?
Thank you in advance!

Try it with double quotes.

ThisWorkbook.Worksheets(4).Range("D2").Formula = "=IFERROR(VLOOKUP($A$2;'[Daily Tracker.xlsx]Info'!$A:$I;2;FALSE);"""")"

Howard
 
Upvote 0
Hi @Osvaldo Palmeiro and @L. Howard,

Thank you both! This is working just fine now with your suggestions.
I still don't understand the comma/semicolon since on the spreadsheets I actually need to use ; in the formulas... and that's what the VBA is pasting there. Whatever!

Cheers!
 
Upvote 0
@Osvaldo Palmerio, I assumed the OP is using a European version of Excel, where the semicolon is standard.
Howard

@no_Fate
I think you could use semicolon since you use FormulaLocal (see below), but using just Formula you should use colon besides your version beeing European.


this should work
Code:
ThisWorkbook.Worksheets (4) .Range ("D2") FormulaLocal = "=IFERROR(VLOOKUP($A$2;'[Daily Tracker.xlsx]Info'!$A:$I;2;FALSE);"""")"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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