Day (date) function then call macro

Musto85

New Member
Joined
Mar 6, 2022
Messages
21
Platform
  1. Windows
Hi all!

I have the code below that calls a macro on the 20th of every month but only once by adding and clearing date on cell C3 based on IF's

Is there a way I can modify it so that it can do that also on the 21st of the month but again only if on the 20th that macro hadn't been called?
The reason I would like that is because sometimes the spreadsheet doesn't get opened on the 20th so I would still like the macro to be called the next day.

Thanks in advance!


VBA Code:
 If Day(Date) <> 20 Then
    Cells(1, 3).ClearContents
            
    GoTo Fine
        
    End If
    
    If Day(Date) = 20 And Cells(1, 3).Value <> "" Then GoTo Fine
    If Day(Date) = 20 And Cells(1, 3).Value = "" Then
    Cells(1, 3).Value = Date + Time

Call Macro
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You should be able to change these formula parts:
VBA Code:
If Day(Date) <> 20
to this:
VBA Code:
If (Day(Date) <> 20) or (Day(Date) <> 21)
to run on either the 20th or 21st.
 
Upvote 0
I solved it like this:

VBA Code:
 If Day(Date) <> 20 And Day(Date) <> 21 Then
    Cells(1, 3).ClearContents
            
    GoTo Fine
        
    End If
    
    If Day(Date) = 20 And Cells(1, 3).Value <> "" Then GoTo Fine
    If Day(Date) = 21 And Cells(1, 3).Value <> "" Then GoTo Fine
    If Day(Date) = 20 And Cells(1, 3).Value = "" Then
    Cells(1, 3).Value = Date + Time

Call Macro
    
End If
    
    If Day(Date) = 21 And Cells(1, 3).Value = "" Then
    Cells(1, 3).Value = Date + Time
    
Call Macro

End If
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top