Having some trouble with dates

Flammy

Board Regular
Joined
Apr 19, 2011
Messages
51
Code:
Dim ADate As Date
Dim AADate As Long

  ADate = TextBox1.value
  AADate = ADate

If BBDate > 40909 Or BBDate < 39236 Then
    MsgBox "Please enter a date between June 3rd 2007 and January 1st 2012 in the second text box"
    Exit Sub
End If
This runs but incorrectly tells me the date I feed it (textbox1) is outside the range when I know it is not. Have I dim'ed something incorrectly?

Annoyingly, I have a nearly identical function which I copy/pasted to create this, and it works fine.

Thanks in advance.
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Shouldn't the If statement be checking ADate (or AADate)? Also, use DateValue for dates rather than those magic numbers.
 
Upvote 0
Oh yeah I have two of these, I removed all the other stuff I guess I deleted the If statement with the wrong variable. both are identical and not working. I'll try switching Adate and AAdate.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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