Advance By Month With A CommandButton

M

Minitman

Greetings,

I have a worksheet with a date in C10 in mmm/yyyy formant. I made a
CommandButton (NextMonth) to advance the date by 1 month. I have a
problem, I used +30 to advance which works for the short term.
However, I am going back 12 years and getting a lot of errors in the
date.

Is there anyway to advance by one month at a time?

Any help would be appreciated.

TIA

-Minitman
 
M

Myrna Larson

One way:

With ActiveSheet.Range("C10")
.Value = DateAdd("m",1,.Value)
End With

Another way

With ActiveSheet.Range("C10")
d = .Value
.Value = DateSerial(Year(d), Month(d) + 1, Day(d))
End With
 
B

Bob Phillips

There is a problem here if the following month has less days (31st Jan + 1
month = 31st Feb, or 2nd Mar), so this formula goes back to the last day of
the previous month. Not perfect but

=DATE(YEAR(C1),MONTH(C1)+1,MIN(DAY(C1),DAY(DATE(YEAR(C1),MONTH(C1)+2,0))))
 
B

Bob Phillips

oops missed the button bit.

--

HTH

RP

Myrna Larson said:
One way:

With ActiveSheet.Range("C10")
.Value = DateAdd("m",1,.Value)
End With

Another way

With ActiveSheet.Range("C10")
d = .Value
.Value = DateSerial(Year(d), Month(d) + 1, Day(d))
End With
 

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