End of Month Function in Visual Basic

  • Thread starter Thread starter Fredriksson via OfficeKB.com
  • Start date Start date
F

Fredriksson via OfficeKB.com

I would like to initialize a text box in a user form with the last day of the
month calculated from the current date (Today)

I tried the following:

Private Sub UserForm_Initialize()
Me.AcctPeriodInputBox.Value = EOMONTH(Date)
End Sub

How do I use Functions that are in Excel to calculate values in a macro?
 
If you are using VBA anyway, there's no need for external functions:

Public Function LastDayOfMonth(WhichMonth As Date) As Date
LastDayOfMonth = DateSerial(Year(WhichMonth), Month(WhichMonth) + 1, 0)
End Function

Adjust the argument/return value for your needs.

NickHK
 
Thank you for your suggestion
If you are using VBA anyway, there's no need for external functions:

Public Function LastDayOfMonth(WhichMonth As Date) As Date
LastDayOfMonth = DateSerial(Year(WhichMonth), Month(WhichMonth) + 1, 0)
End Function

Adjust the argument/return value for your needs.

NickHK
I would like to initialize a text box in a user form with the last day of the
month calculated from the current date (Today)
[quoted text clipped - 6 lines]
How do I use Functions that are in Excel to calculate values in a macro?
 

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