Hi All
I'm trying to write a macro that will look at 12 monthly sales columns
and sum the year to date sales.
I think I'm defining the month as a variable with..
Dim Mon As Integer
Mon = Month(today)
But I get very stange results when I use this to calculate the
sales...
Range(quot;W1quot;).Select
ActiveCell.FormulaR1C1 = quot;Sales LYTDquot;
With ActiveSheet.Range(quot;W2:Wquot; amp; LastRow)
.FormulaR1C1 = quot;=SUM(RC[-12]:RC[-quot; amp; (12 - Mon) amp; quot;])quot;
End With
Any idea what I need to change?
Thanks
Colin (ever amazed by my own lack of knowledge!)--
Colin Vicary
------------------------------------------------------------------------
Colin Vicary's Profile: www.excelforum.com/member.php...oamp;userid=10472
View this thread: www.excelforum.com/showthread...hreadid=515414You have a syntax error
Mon = Month(today)
should
Mon = Month(Date)
that apart, it works fine for me.
--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
quot;Colin Vicaryquot; gt;
wrote in message
...
gt;
gt; Hi All
gt;
gt; I'm trying to write a macro that will look at 12 monthly sales columns
gt; and sum the year to date sales.
gt;
gt; I think I'm defining the month as a variable with..
gt;
gt; Dim Mon As Integer
gt; Mon = Month(today)
gt;
gt; But I get very stange results when I use this to calculate the
gt; sales...
gt;
gt; Range(quot;W1quot;).Select
gt; ActiveCell.FormulaR1C1 = quot;Sales LYTDquot;
gt; With ActiveSheet.Range(quot;W2:Wquot; amp; LastRow)
gt; FormulaR1C1 = quot;=SUM(RC[-12]:RC[-quot; amp; (12 - Mon) amp; quot;])quot;
gt; End With
gt;
gt; Any idea what I need to change?
gt;
gt; Thanks
gt;
gt; Colin (ever amazed by my own lack of knowledge!)
gt;
gt;
gt; --
gt; Colin Vicary
gt; ------------------------------------------------------------------------
gt; Colin Vicary's Profile:
www.excelforum.com/member.php...oamp;userid=10472
gt; View this thread: www.excelforum.com/showthread...hreadid=515414
gt;
Genius!
Thanks Bob
Colin--
Colin Vicary
------------------------------------------------------------------------
Colin Vicary's Profile: www.excelforum.com/member.php...oamp;userid=10472
View this thread: www.excelforum.com/showthread...hreadid=515414
- Jul 20 Thu 2006 20:08
Defining quot;Monthquot; as a variable in VBA
close
全站熱搜
留言列表
發表留言