Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am trying to create a little vba macro that calculates the number of the
month as well as the name of the month for use later in calculations. I havethe following: XLMonth = Month(Date) XlMonth2 = Format(Date, "mmm") So I figure I can if/then statement the whole thing, but it is the "else" part that I am having trouble with. I need to move back a month (-1) if a condition set earlier is met. But when I subtract (-1) from XlMonth I get zero and noth 12. How do I work around this. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
XLMonth = Month(Date)-1
If XLMonth = 0 Then XLMonth = 12 -- HTH RP (remove nothere from the email address if mailing direct) "Jeff" wrote in message ... I am trying to create a little vba macro that calculates the number of the month as well as the name of the month for use later in calculations. I havethe following: XLMonth = Month(Date) XlMonth2 = Format(Date, "mmm") So I figure I can if/then statement the whole thing, but it is the "else" part that I am having trouble with. I need to move back a month (-1) if a condition set earlier is met. But when I subtract (-1) from XlMonth I get zero and noth 12. How do I work around this. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Another option is to use the DateSerial function:
Sub test() Dim daDateLastMonth As Date daDateLastMonth = DateSerial(Year(Date), Month(Date) - 1, Day(Date)) MsgBox Month(daDateLastMonth), , _ Format(daDateLastMonth, "mmmm") End Sub RBS "Jeff" wrote in message ... I am trying to create a little vba macro that calculates the number of the month as well as the name of the month for use later in calculations. I havethe following: XLMonth = Month(Date) XlMonth2 = Format(Date, "mmm") So I figure I can if/then statement the whole thing, but it is the "else" part that I am having trouble with. I need to move back a month (-1) if a condition set earlier is met. But when I subtract (-1) from XlMonth I get zero and noth 12. How do I work around this. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Subtraction Question | Excel Discussion (Misc queries) | |||
Excel subtraction question | Excel Discussion (Misc queries) | |||
Newbie Question - Subtraction Formula Question | Excel Discussion (Misc queries) | |||
Subtraction question | Excel Discussion (Misc queries) | |||
Subtraction Question | Excel Discussion (Misc queries) |