How do I display an message box if the date is in the past?

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,392
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
When entering a date, how do I display a message box that asks for confirmation to continue if the date is in the past?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You may need to use VBA for this, but have a look at Data Validation first. It may be a simpler way to do it !!
 
Upvote 0
The data validation works but I need a message to be displayed if the date is before the current date, asking if you really want to post a date in the past and asking for confirmation.
 
Upvote 0
Upvote 0
Maybe this in the sheet module....modify range to suit

Code:
Sub worksheet_change(ByVal target As Range)
Dim cell As Range
Application.EnableEvents = False
        If Range("A1").Value < Date Then
            MsgBox "This input is older than today !....Are you sure that is what you want ???"
        End If
Application.EnableEvents = True
End Sub
 
Upvote 0
The date is in the first column of a table called npss_quote. How would I reference that in the above code? The column is called date.
 
Upvote 0
Maybe I should explain this a little better. This is for an invoice sheet with multiple lines on it so there are multiple dates. I thought I would need to know how to reference the date column using vba so I could reference the current cell that has the date entered. How would I do this?

Here is the code:
Sub worksheet_change(ByVal target As Range)
Dim cell As Range
Application.EnableEvents = False
If Range("A1").Value < Date Then
MsgBox "This input is older than today !....Are you sure that is what you want ???"
End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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