Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Colin Vicary
 
Posts: n/a
Default Defining "Month" as a variable in VBA


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("W1").Select
ActiveCell.FormulaR1C1 = "Sales LYTD"
With ActiveSheet.Range("W2:W" & LastRow)
.FormulaR1C1 = "=SUM(RC[-12]:RC[-" & (12 - Mon) & "])"
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: http://www.excelforum.com/member.php...o&userid=10472
View this thread: http://www.excelforum.com/showthread...hreadid=515414

  #2   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Defining "Month" as a variable in VBA

You 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)

"Colin Vicary"
wrote in message
...

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("W1").Select
ActiveCell.FormulaR1C1 = "Sales LYTD"
With ActiveSheet.Range("W2:W" & LastRow)
FormulaR1C1 = "=SUM(RC[-12]:RC[-" & (12 - Mon) & "])"
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:

http://www.excelforum.com/member.php...o&userid=10472
View this thread: http://www.excelforum.com/showthread...hreadid=515414



  #3   Report Post  
Posted to microsoft.public.excel.misc
Colin Vicary
 
Posts: n/a
Default Defining "Month" as a variable in VBA


Genius!

Thanks Bob

Colin


--
Colin Vicary
------------------------------------------------------------------------
Colin Vicary's Profile: http://www.excelforum.com/member.php...o&userid=10472
View this thread: http://www.excelforum.com/showthread...hreadid=515414

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Twist on the variable rate problem [email protected] Excel Worksheet Functions 0 January 23rd 06 10:41 AM
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
object variable or with block variable not set Diego Excel Discussion (Misc queries) 1 August 9th 05 02:46 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
I Need VBA Assistance for global variable question Brent E Excel Discussion (Misc queries) 1 March 1st 05 08:46 PM


All times are GMT +1. The time now is 04:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"