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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
So your saying you do not know how to install this script into a button and then click the button?
This is not a sheet activate script.
You put this type script in a button
 
Upvote 0
You said the script worked then you said it did not work.
So I suggest this:
Close the workbook do not save changes.
Open new workbook.
Put script in new workbook and try again.

If you want to use sheet change event scripts and you have other scripts in you sheet you may have errors.

We would need to see all the scripts you have in this sheet.
 
Upvote 0
When you open the Visual basic window(usually ALT + F11)...
Press CTRL + G to open the immediates window.
copy this
Code:
Application.EnableEvents = True
into that window and press Enter.
Save and Close.....now see if the worksheet code runs !
 
Upvote 0
I originally put the code into some event on the spreadsheet, thinking it will always be resetting and that didn't seem to work but I just put it into a button and tried it and it worked!! Yay!! Thanks!!
 
Last edited:
Upvote 0
When I put a date in that is before the current date, and say i want to keep it, it formats the date as 1-01-2018 but I have my other date cells formatted as 01-01-18. How do I make them look the same?

This is the code I have:

Private Sub Worksheet_Change(ByVal Target As Range)
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

Thanks.
 
Upvote 0
What is stopping me adding the code to the add line button, so it is reset with every line that is added? Does that sound like a good idea?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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