last day of the month

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to automatically fill a variable with the last day of the
month based on the month in another variable?

For example, if var1 = 9, is there a way to program var2 = 9/30/2005 or if
var1 = 8, then var2= 8/31/2005

Thanks.......
 
Hi JT,

Try something like:

Sub AAA()
Dim var As Long
Dim LastDayOfMonth As Date

var = 8

LastDayOfMonth = DateSerial(Year(Date), var + 1, 0)
MsgBox LastDayOfMonth

End Sub
 
This is weird:
In Bob's reply I see "var2 = dateserial(2005,var1,0)" and was going to
correct it.
But then noticed in JT's quoted reply to Bob "var2 =
dateserial(2005,var+1,0)", correct.

Is it just my OE reader or anyone else seeing the same ?

NickHK
 
Nick, I had something like that the other day.

I posted a response, and the OP had a problem because parts of the text just
disappeared. I re-posted with the full text and she had no problem then.
 

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

Back
Top