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

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,375
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?
 
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


based on your explanation, I would recommend that you use Data validation on the particular cell/s like I suggested before.
(still, just a suggestion)
thank you..
https://www.dropbox.com/s/no5564zipx...-date.PNG?dl=0
https://www.dropbox.com/s/6zrms5x4xf...date1.PNG?dl=0
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
This will work for any cell in column A
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  9/4/2018  10:05:48 PM  EDT
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Application.EnableEvents = False
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Value < Date Then
ans = MsgBox("This input is older than today !....Are you sure that is what you want ???", vbYesNo)
If ans = vbNo Then Target.Value = ""
End If
End If
Application.EnableEvents = True
End Sub
 
Upvote 0
Do I need to change Worksheet_change to (name of sheet)_change?
 
Upvote 0
No. Put this script in the sheet with your data.

If it stopped:
Try creating a script that just says:

Application.EnableEvents = True

And run the script to reset EnableEvents
Then try again.

Are you sure your date is going in column A or column (1) of a Table

Column(1) of a table may not be column(A) of a sheet.
You did something that caused a error.


 
Upvote 0
I am putting in that code and now it is not asking anything about the date if it is earlier than the current date. Any ideas why that may be?
 
Upvote 0
Column A is definitely the first column of the table.

So where do I put that script, anywhere in particular?
 
Upvote 0
Well you said earlier it worked.
Did you do this:
I mentioned in my last post:
Run this script to fix the problem:
Code:
Sub Reset_Me()
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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