IsDate is a built-in VBA function that tells you whether a value can be interpreted as a date or time. It returns True or False, so If IsDate(Range("A1").Value) Then is the shortest way to guard date code against text, blanks and errors. Because it accepts real dates, date-like text such as "12/04/2026", and even valid time strings, it is the standard gate before CDate, Format or date arithmetic.
What You'll Need
- Excel on Windows or Mac with macros enabled. The VBA editor opens with Alt+F11 (Windows) or Opt+F11 (Mac). Menu names can differ slightly by Excel version and region, but
IsDateitself behaves the same. - A workbook saved as .xlsm if you want to keep the code. Standard .xlsx files drop macros on save.
- Macro security set to allow macros, via File > Options > Trust Center > Trust Center Settings > Macro Settings (Windows). If your organisation blocks macros, ask your admin rather than changing policy.
- Test data in cells you can safely edit. Work on a copy if the sheet holds live data.
Step-by-Step
- Open the editor and insert a module. Press Alt+F11, then right-click your project in the Project Explorer and choose Insert > Module. Code in a module is reusable; code behind a sheet only runs for that sheet's events.
- Write a minimal test subroutine. Type:
Place a date in A1 and run with F5. The message box shows the interpreted date.Sub CheckDate() Dim v As Variant v = Range("A1").Value If IsDate(v) Then MsgBox "Valid date: " & CDate(v) Else MsgBox "Not a date" End If End Sub - Understand what IsDate accepts and rejects. It returns
Truefor a real Excel date, for text that the system recognises as a date or time ("4 Dec 2026", "16:30"), and for numbers inside the valid date range such as 46000. It returnsFalsefor empty cells, error values, ordinary text like "hello", and numbers outside the representable range. Note that an uninitialised Variant isFalse, but a variable holdingEmpty(for example an empty cell) is alsoFalse, which is usually what you want. - Declare your variable as Variant for cell values.
IsDateneeds a Variant argument.Range("A1").Valuealready returns a Variant, but if you declareDim d As Dateand passd, you get a type mismatch before the check. Keep the raw value in a Variant, test it, then convert. - Test before converting. Never call
CDateon unchecked input. A string like "not a date" raises run-time error 13. The safe pattern is:If IsDate(v) Then d = CDate(v) ' do date work here End If - Loop over a column. To flag every bad row in a range:
TheDim c As Range For Each c In Range("B2:B100") If Len(Trim(CStr(c.Value))) > 0 And Not IsDate(c.Value) Then c.Interior.Color = vbYellow End If Next cLen(Trim(...))check stops blanks being flagged; blanks read as not-a-date, which is technically correct but noisy. - Return a result to the sheet instead of a message box. Replace the
MsgBoxwith something likeRange("C1").Value = IsDate(Range("A1").Value)so you get TRUE/FALSE in a helper column for filtering. - Wrap the test in error handling for stubborn inputs.
IsDaterarely errors, but a cell containing an error value can propagate. Put the test insideOn Error Resume Next...On Error GoTo 0around a helper function, and returnFalsewhenErr.Number <> 0, clearingErrafterwards. - Save and re-run with representative data. Test a real date, a date typed as text, a blank, a number, a time only, and a nonsense string. Confirm each gives the expected TRUE/FALSE before trusting the routine on a full sheet.
Common Mistakes
- Using a worksheet cell formula instead of the function. Excel's sheet function is
ISNUMBERcombined with a date check;IsDateis VBA-only. Typing=ISDATE(A1)in a cell gives a name error. - Assuming IsDate validates the format. It asks whether the value can be read as a date, not whether it is a real calendar date or matches your expected layout. "13/45/2026" may or may not pass depending on the system locale, and ambiguous input like 03/04/2026 is accepted as either the 3rd of April or 4th of March depending on regional settings.
- Declaring the variable as Date or String. Type mismatch errors follow. Use Variant.
- Forgetting that blank cells fail the test. If blanks are legitimate, test for them separately before flagging rows as invalid.
- Ignoring locale. Code that works on your machine can misread dates on a colleague's machine set to a different date format. Where precision matters, parse the string yourself or store dates as real dates.
- Calling IsDate on a whole range.
IsDate(Range("A1:A10"))does not check every cell; it evaluates the array as a single value and gives unpredictable results. Loop, or pass one cell at a time.
Tips
- To require a real date and reject date-like text, add
IsDate(v) And VarType(v) = vbDate. This distinguishes true serial dates from strings that merely look like dates. - Timer and time-only values pass
IsDate. If you need a full date, also check that the value is greater than or equal to 1. - Combine with
IsNumericwhen you need to tell a serial number from a text date: a number that passesIsDateis a serial date, not meaningful text. - Use a small helper function such as
Function IsRealDate(v As Variant) As Booleanso the same logic can be reused across modules and changed in one place. - Test with the system date format your users actually use, not only your own regional setting.
Troubleshooting
Run-time error 13 (type mismatch). You are passing a strongly typed Date, or calling CDate on a value that failed the check. Confirm the variable is Variant and that CDate sits inside the If IsDate(...) branch.
IsDate returns True for something you expected to be rejected. Check the string in the Immediate window with ?IsDate(Range("A1").Value) and inspect its type with ?VarType(...). Text that your regional settings accept as a date will pass. If you need a stricter test, validate the string pattern or require VarType = vbDate.
IsDate returns False for an obvious date. The value may be stored as text with leading spaces, a non-breaking space, or a trailing character. Try Trim, or check whether the cell holds an error value. If the whole column fails, the data may have been imported as text; convert it to real dates before running your code.
The macro does not appear to run at all. Macros may be disabled. Check the Trust Center settings and confirm the file is saved as .xlsm. If your organisation blocks macros, ask IT rather than attempting to bypass the policy.
Dates come out swapped between day and month. That is a locale issue, not an IsDate bug. Normalise the data or parse the pieces explicitly.
Frequently Asked Questions
Is there an IsDate function in worksheet formulas?
No. IsDate exists only in VBA. In a worksheet you can test a value with ISNUMBER for real serial dates, or combine ISERROR with DATEVALUE for text dates.
Does IsDate catch invalid dates like 31 February?
It accepts text that the system can convert to a date; whether an impossible date is rolled over or rejected depends on how it is parsed, so do not rely on IsDate as a full calendar validator. Confirm with CDate and check the result.
Why does IsDate return True for a plain number?
Excel stores dates as serial numbers, so a number within the valid date range is a legitimate date value. If you only want true date-typed values, add VarType(v) = vbDate.
Can IsDate check time-only values?
Yes. Strings or numbers that represent a time pass the test. Remember that a time-only value has a date portion of zero, which can matter in calculations.
Does IsDate depend on Windows regional settings?
Yes. It uses the system locale to interpret ambiguous text dates, so the same string can pass on one machine and fail on another. Store dates as real dates to avoid surprises.
What does IsDate return for an empty cell?
False. If blanks are acceptable in your data, test for them first and skip those rows so your report only flags genuine problems.