C
Cimjet
With VBA I need to detect the last weekday of each month. I need that to trigger an event macro on the last workday of each month.
Regards
Cimjet
Regards
Cimjet
To detect the last workday of the month in VBA, you can use:
Dim dLastWDOM As Date
dLastWDOM = WorksheetFunction.WorkDay(DateSerial(Year(Date), Month(Date) + 1, 1), -1)
If Date = dLastWDOM Then
...
Glad to help.
But please note that if you will be using this in versions of Excel prior to 2007, a different algorithm will be required, as the Workday was part of the Analysis ToolPak (and not a built-in worksheetfunction) prior to Excel 2007.
Post back if that might be an issue.
Hi RonOK, let me see if I can remember this. And I can't test it as I don't have Excel 2003 installed.
In Excel 2003, the WORKDAY function is part of the Analysis Tool Pak. To use it in VBA, do the following:
Open Excel; and select Tools/Add-Ins
Select: Analysis ToolPak - VBA (If that is not there, you will have to browse for it; try something like C:\Program Files\Microsoft Office\Office\Library or do a search)
Then open the VBA Editor.
Select Tools/References
Select the reference to atpvbaen.xls
You should now be able to use the Workday function directly in your VBA macro. So, in the macro, remove the "worksheetfunction." before the Workday, so it looks like:
dLastWDOM = WorkDay(DateSerial(Year(Date), Month(Date) + 1, 1), -1)