Macro with Message Box for Date Greater Than Today

rhmkrmi

Active Member
Joined
Aug 17, 2012
Messages
348
Office Version
  1. 365
Platform
  1. Windows
Hi there, I need a VBA to be used in Excel to check a couple of columns (F:F, H:H, N:N) to see if any cell in those columns contain a date that is greater than today and pop up a message. Could you please help?

Thank you.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
If Application.WorksheetFunction.Max(Columns("F"), Columns("H"), Columns("N")) > Date Then MsgBox "a message"
 
Upvote 0
Thanks Fazza.

I am using a text format for my dates (TEXT(F10,"dd-mmm-yyyy")).
How can the code be changed to pick up this format as well as a true date format?

Thank you.
 
Upvote 0
That isn't a text format: it is text. Not a date as far as Excel is concerned. The code doesn't need changing.

The formula refers to column F so column F presumably really does contain a date. And again the code should be fine.

The code is independent of formats. For example, enter 44444 in a cell. It can be formatted (CTRL-1) as number like 44,444 or a date like 5-Sep-21

However using a TEXT formula returns text.
 
Upvote 0
PS,

If you have text instead of dates here are some ways to convert them to numbers so Excel handles them as dates,
=value(a1)
=a1*1
=a1+0
 
Last edited:
Upvote 0
Thanks a lot for all the tips. I will try them.

In the meantime, can I also ask how I can use the code that you provided in Sheet1 but reference it to the same columns in Sheet2?

In Sheet2 I have dates but in Sheet1 I have converted them to text because that especial format is required.

Thanks again.
 
Upvote 0
you can add the reference to Sheet2

if Sheet2 is the code name

If Application.WorksheetFunction.Max(Sheet2.Columns("F"), Sheet2.Columns("H"), Sheet2.Columns("N")) > Date Then MsgBox "a message"
 
Last edited:
Upvote 0
Thank you.

I am using this but it pops up a message when I enter a future date in any field!

Private Sub Worksheet_Change(ByVal Target As Range)


If Application.WorksheetFunction.Max(Columns("F"), Columns("H"), Columns("N")) > Date Then MsgBox "Please check your dates"


End Sub

What am I doing wrong?

Thank you.
 
Upvote 0
Maybe there is already - before the data entry that triggers the macro - a future date in one of the columns of interest?
 
Upvote 0

Forum statistics

Threads
1,224,910
Messages
6,181,675
Members
453,061
Latest member
schiefA

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