How can I use the " character in a string

G

Guest

I'm programming a macro in Visual Basic and want the macro to insert a
formula in the worksheet using the ActiveCell.FormulaR1C1 property. I want
the formula to include an empty string, like this:
=IF(ISBLANK(A1);A1+8;"")
so that the cell is empty if A1 is blank, and otherwise the result of the
formula.

ActiveCell.FormulaR1C1 = "=IF(ISBLANK(A1);A1+8;"")"
is what I have attempted, but obviously this won't work as the " character
will end and restart the string without leaving " characters. How can I go
about having the " character included in the string?
 
G

Gary Keramidas

try this, i change the semi colons to commas, though. you need to double up on
the quotes

ActiveCell.Formula = "=IF(ISBLANK(A1),A1+8,"""")"
 
A

aidan.heritage

When you have a problem like this one, it's always worth using the
macro recorder to see what is generated - in this instance, it would
give you EXACTLY what you needed - also, worth mentioning that
formulaR1C1 would need R1C1 instead of A1 (if you want to use A1,
change it to just Formula
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top