Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing a date in excel 1

Status
Not open for further replies.

FontanaS

Programmer
May 1, 2001
357
US
I would like to check the value in a cell to see if it is a date or not. so far i have the following code that does not work.


Len(ws.Range("C" & iRow).Text) = Date


any suggestions?
 
The problem is that the underlying data for a date is a number. Whether you 'see' a date or not is just a case of formatting.

Todays date is seen by excel as 36978 days after 1 jan 1900. I don't know what the upper limit is, but any number you enter will be considered as a date by excel.

Can you explain what you are comparing, and I'm sure a solution can be made in another way.

 
You could check using a string and IsDate function:
Code:
Sub Check()
    Dim sValue As String
    sValue = Range("A1").Text
    If IsDate(sValue) = True Then
        MsgBox "It's a Date!"
    Else
        MsgBox "It's NOT a Date!"
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top