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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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