Using quotes and curly brackets in formulas for vba

oaishm

Board Regular
Joined
Jan 30, 2009
Messages
97
I'd like to enter in an equation such as this into a cell:
{=SUM(IF(LEFT(D8:D17,3)="130",E8:E17,0))}

in VBA. There are two issues. First, when I build up a string, I normally can't have quotes "". In php, this is simple, use single quotes instead, such as cell.formula = '{=sum(if(left(".range.address.",3)="130",'.newrange.address. etc.

How do I do that here? Do I escape out of the quotes?

Further, you'll note the curly brackets. I can't just put in curly brackets, right? Do I have to do something else? Maybe the macrorecorder has an answer.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
1) Use FormulaArray property instead of just Formula
2) Need extra set of double quotes when it is used in the formula

try

Code:
Cells(1,1).FormulaArray = "=SUM(IF(LEFT(D8:D17,3)=""130"",E8:E17,0))"
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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