Solved EXCEL Convert date to number

August 2, 2012 at 08:21:04
Specs: Windows XP
Ok what Im trying to do sounds very simple... I just cant get to the right format.

Lets say I have a date like 8/2/12 or 12/31/12

I need to make an if condition where if the date is after lets say 10/31/12 the user would get a pop up error message saying to use a current version.

Im just trying to force users to keep up with the current forms that I realize to them, caus ethey just keep using the old versions caus ethey are lazy as hell.

I know how to make the if condition and the error pop up message.

I just need Excel to convert the date into numbers like 8/2/12 = 41123 in the background without showing it.

So if the date is 10/31/12 = 41213 I want excel to stop the process and give an error message to the user.

Something like

CurrentDate = 08/02/12
If (CurrentDate) > 41213 then
MsgBox "Dude use the current form"
About 4 pages of code
End If

Note: when I take the date from another screen it comes as "08/02/12"
Always 8 characters

Thanks in advance!!!

See More: EXCEL Convert date to number

Report •

August 2, 2012 at 10:59:37
✔ Best Answer
This code should get you what you asked for, but I think you are making it more complicated than it has to be.

Sub CompareDateSerials()
  DealDate = "8/2/12"
    dVal = DateValue(DealDate)
      dSer = Format(dVal, "####")  'returns date as serial number (41123)
        If dSer > 41213 Then
         MsgBox "Dude use the current form"
        End If
End Sub

However, you don't need to convert it to the serial number. You can just compare the DateValues.

Sub CompareDateValues()
  DealDate = "8/2/13"
    If DateValue(DealDate) > DateValue("10/31/12") Then
       MsgBox "Dude use the current form"
    End If
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •

August 2, 2012 at 12:23:04
Awesome man, works perfectly!!!

Thanks a lot!!!!!!!

Report •

Related Solutions

Ask Question