Write cell formula w VBA

StanSz

Board Regular
Joined
Sep 18, 2004
Messages
199
I've written several formulas via VBA without issue, but I'm having a problem with 2 formulas. I thought I had a resolution of the issue using a solution found on an Excel VBA site but that has not resolved the problem:

Here's what I have as the VBA code for testing. I'm getting a 'RunTime 1004 error' in the two last lines:

Sub Testing()

Dim i As Integer
Dim zFormula As String
Dim aeFormula As String

i = 11

zformula = "=IF(F11="",0,-F11*(E11*100))"
aeFormula = "=IF(D11<>"",D11/I11,"")"

Range("Q" & i).Formula = zFormula 'Gives Runtime error 1004

Range("S" & i).Formula = aeFormula 'Gives Runtime error 1004

End Sub

Any thoughts or solutions ??

Thanks

Stansz
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Stansz

You need to double up the quotes in the formulas, try this.
Code:
zformula = "=IF(F11="""",0,-F11*(E11*100))"
aeFormula = "=IF(D11<>"""",D11/I11,"""")"
 
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,965
Members
449,201
Latest member
Jamil ahmed

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