writing a formula using VBA

G

Greg

I am trying to make a macro that will write a formula to a cell. I am using
the code below but running into an issue with it.

ActiveCell.Formula =
"=SUMPRODUCT(SUBTOTAL(3,OFFSET(L6:L2000,ROW(L6:L2000)-MIN(ROW(L6:L2000)),,1))*(L6:L2000="Yes"))"

it acts like all of it is going to work until it gets to the ="Yes" part of
the code and then it expects the first " to be the end of the formula. How
else can I get a macro to write
=SUMPRODUCT(SUBTOTAL(3,OFFSET(L6:L2000,ROW(L6:L2000)-MIN(ROW(L6:L2000)),,1))*(L6:L2000="Yes")) into cell B2?

Thank you for your help.
Greg
 
N

Niek Otten

Hi Greg,

For quotes qithin quotes, use two quotes

"=SUMPRODUCT(SUBTOTAL(3,OFFSET(L6:L2000,ROW(L6:L2000)-MIN(ROW(L6:L2000)),,1))*(L6:L2000=""Yes""))"
 
H

Harald Staff

HI Greg

Double the quotes around text:
...))*(L6:L2000=""Yes""))"

HTH. Best wishes Harald
 

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