Using a variable in a VBA formula

C

Colin Vicary

Hi all

I have a worksheet tht contains year to date sales and sales for las
year. I want to show those sales as "last year to date". This means
have to know how far through the year we are!

I've set a variable to get that, but now I want to add it to th
formula in the macro.

I've tried this but it's wrong, can anyone tell me how to make i
right?

Thanks

Colin

Dim Mon As Integer
Mon = Month(today) - 1
ActiveCell.FormulaR1C1 = "=SUM(RC[(Mon-12)]:RC[-5])
 
B

Bob Phillips

Colin,

You have to separate the variable from the text

ActiveCell.FormulaR1C1 = "=SUM(RC[" & (Mon-12) & "]:RC[-5])"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Colin Vicary" <[email protected]>
wrote in message
news:[email protected]...
 

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