ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   End of Month Function in Visual Basic (https://www.excelbanter.com/excel-programming/381851-end-month-function-visual-basic.html)

Fredriksson via OfficeKB.com

End of Month Function in Visual Basic
 
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?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200701/1


merjet

End of Month Function in Visual Basic
 
Precede them by Application. or Application.WorksheetFunction.

Hth,
Merjet


NickHK

End of Month Function in Visual Basic
 
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

"Fredriksson via OfficeKB.com" <u27002@uwe wrote in message
news:6cc6f82b6e6b0@uwe...
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?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200701/1




Fredriksson via OfficeKB.com

End of Month Function in Visual Basic
 
Thank you for your suggestion
merjet wrote:
Precede them by Application. or Application.WorksheetFunction.

Hth,
Merjet


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200701/1


Fredriksson via OfficeKB.com

End of Month Function in Visual Basic
 
Thank you for your suggestion

NickHK wrote:
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?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200701/1



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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com