Syntax for writing a formula to a cell

G

Guy Hoffman

I am attempting to write this formula to a cell from VBA:

Worksheets("Summary").Range("H18").Formula = "=cell("contents",b53)"

But because the worksheet formula also uses double quotes as part of
its syntax, I am getting a compile error as VBA thinks the second
double quote (next to the word "cell" is the end of the statement.

I tried using a single quote but to no avail.

How do you fix this?

GH
 
B

Bernard V Liengme

Replace each double quote by a pair of double quotes.
I discovered this by recording a macro that performed the operation you
asked about.
Bernard
 
P

Peo Sjoblom

Use double quotes, i.e.

Worksheets("Summary").Range("H18").Formula = "=cell(""contents"",b53)"
 
B

Bob Phillips

Guy,

Try this

Worksheets("Summary").Range("H18").Formula = "=cell(""contents"",b53)"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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