Input Box with Values and Dates

ADSkinner

New Member
Joined
Aug 18, 2018
Messages
19
Hello all.

I have created a drop down list with specific entries I want to allow, one of which being a date.

As the user then selects the option of "Date" I have added the code below, however what I am looking to have it accomplish is that no date earlier than today is allowed as their entry. They must always enter a future date.
When running this code, it accepts future dates as well as past dates. Is there something that I am missing?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("$D$1:$D$10")) Is Nothing Then Exit Sub
On Error GoTo Trap
Dim rspn As Variant
Application.EnableEvents = False
If Target = "Date" Then
   rspn = InputBox("Enter a valid date")
      If rspn > Date Then
          Target = rspn
      Else: MsgBox "Invalid Date"
      End If
      
End If
Trap: Application.EnableEvents = True
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Change this variable declaration:
Code:
Dim rspn As Variant
to this:
Code:
Dim rspn As Date
and it will work.
 
Upvote 0
You are welcome.
By delcaring as "Variant", Excel was converting it to Text, so your value check wasn't working correctly.
 
Upvote 0

Forum statistics

Threads
1,223,727
Messages
6,174,144
Members
452,547
Latest member
Schilling

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