Formula into cells from VBA help please!

A

anon

Hi,

I want to put this formula into a cell via VBA;

=IF(C4 = 5,"ACTIVATED","NOT ACTIVATED")

However this would mean the code would be;

range("c4").formula = "=IF(C4 = 5,"ACTIVATED","NOT ACTIVATED")"

which will cause me errors because of the "" enclosed in the formula.
I'd appreciate if anyone could clear this up for me. Thanks,
 
B

Bob Phillips

Range("c4").formula = "=IF(C4 = 5,""ACTIVATED"",""NOT ACTIVATED"")"


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
R

Rick Rothstein \(MVP - VB\)

Quote marks delineate String constants (text) in VB, so the internal quote
marks are confusing the VB compiler. VB does provide a mechanism to include
quote marks within a String... double them up. So, wherever you need a quote
mark inside a String constant, use two quote marks instead of the one you
would normally use.

Range("c4").Formula = "=IF(C4 = 5,""ACTIVATED"",""NOT ACTIVATED"")"

Note that the outer quote marks are not doubled up... they are the ones that
delineate the String constant; it is only quote marks within them that need
to be doubled up in order to be interpreted as a quote mark character and
not a String delineater.

Rick
 

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