I wonder if anybody can help a bit here, please
I have on a sheet called Calibrations due
cell M3 has the formula =Today()
Cell M4 = last run date of my code, this is part of my code as below, copy current date & paste values only in Cell M4
Cell N4 has the formula =EOMONTH(M4,0)- M4 (this is so I can add the days to get the end of the month)
Cell M5 has the formula =M4+N4 (this gives me the last day of the month)
Cell M6 has the formula =M5+1 (this give me the earliest next run time for the code.
The reason I am doing this is as this is an OnOpen event and I only want the code to run once a month but as near to the first of the month as possible. Obviously as this runs only when opened it could run at anytime during the month from the 1st onwards.
I am having trouble with the line of code below, where it checks if the current date is less than or equal to the last day of the month, if it is I just need to exit the sub. The problem is it exits the sub whether the current date is before or after the last day of the month.
Any help is much appreciated
Any help is always appreciated
I have on a sheet called Calibrations due
cell M3 has the formula =Today()
Cell M4 = last run date of my code, this is part of my code as below, copy current date & paste values only in Cell M4
Cell N4 has the formula =EOMONTH(M4,0)- M4 (this is so I can add the days to get the end of the month)
Cell M5 has the formula =M4+N4 (this gives me the last day of the month)
Cell M6 has the formula =M5+1 (this give me the earliest next run time for the code.
The reason I am doing this is as this is an OnOpen event and I only want the code to run once a month but as near to the first of the month as possible. Obviously as this runs only when opened it could run at anytime during the month from the 1st onwards.
I am having trouble with the line of code below, where it checks if the current date is less than or equal to the last day of the month, if it is I just need to exit the sub. The problem is it exits the sub whether the current date is before or after the last day of the month.
Any help is much appreciated
VBA Code:
If Sheets("Calibration Due").Range("M3") <= ("M5") Then 'This is comparing current date to the end of the month date , if current date is less or equal to end of month exit sub
Any help is always appreciated
VBA Code:
Private Sub Workbook_Open()
'this is running the code to copy & email all equipment that requires calibration
Sheets("Calibration").Select
If ThisWorkbook.ReadOnly = True Then
Exit Sub
End If
Application.ScreenUpdating = False
'Sheets("Calibration Due").Activate
'Sheets("Calibration Due").Visible = True
If Sheets("Calibration Due").Range("M3") <= ("M5") Then 'This is comparing current date to the end of the month date , if current date is less or equal to end of month exit sub
Exit Sub
Else
Sheets("Calibration Due").Visible = True
Sheets("Calibration Due").Activate
Call ListCalibrationDueItems
Call EmailCalibrationDue
Range("M3").Copy 'copying the current date
Range("M4").PasteSpecial xlPasteValues 'pasting current date into last run time
Sheets("Calibration").Select
Sheets("Calibration Due").Visible = False
ActiveWorkbook.Save
Application.ScreenUpdating = True
End If
End Sub