Date Macro

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Depends on how that value got into A1. Was it returned from a formula in A1? Is it manually entered? Part of a hyperlink? Imported from external data? Explain how it got there for a relevant suggestion.
 
Upvote 0
something along these lines?

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)

<SPAN style="color:#00007F">If</SPAN> Target.Address <> "$A$1" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

<SPAN style="color:#00007F">If</SPAN> Day(DateValue(Range("A1")) + 1) = 1 <SPAN style="color:#00007F">Then</SPAN>
    <SPAN style="color:#007F00">'execute code</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Yee, I'm still pretty new at this, but wouldn't the code only fire if A1 was selected at the time A1 changed? Or is that the point?
 
Upvote 0
Thanks for trying but that didn't do it. I need the macro to run if the date in cell a1 is tha last day of any month (Jan 31, Feb 28 etc.). Does anyone know if there is a code for last day of month?

Thanks :oops:
 
Upvote 0
Hi ... dweller:

Let us try ...
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Intersect(Target, [a1]) Is Nothing Then Exit Sub
    If Day([a1]) = Day(DateSerial(Year([a1]), Month([a1]) + 1, 0)) Then Macro
End Sub
The code will fire if the entry in cell A1 is changed so that it is the last day of the month. if it is to be used in a different way, modify it to suit accordingly.
 
Upvote 0
yee - -

Since this is a formula, a Change event won't do it; it'll require a Calc event.

omcd - -

Two questions:

(1)
Is this really for "any month" or only for the current month, or previous month?

(2)
How exactly is A1 formatted, what does the date look like when you see it?
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

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