Check if a valid date?

Guanjin Peter

Active Member
Joined
May 21, 2008
Messages
429
I'm currently using the below code to check if it's blank. Actually I wanted to check if it is a valid date. I can't really use:
=IF(B1=dd-mm-yyyy,TEXT(WEEKDAY(B1),"dddd"),"")
so any idea?

Code:
=IF(B1="","",TEXT(WEEKDAY(B1),"dddd"))
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,231
Office Version
  1. 365
Platform
  1. Windows
Dates are actually stored as Numbers in Excel (specifically, the number of days since 1/1/1900). So you can use the ISNUMBER function, i.e.

=IF(ISNUMBER(B1),TEXT(WEEKDAY(B1),"dddd"),"")
 

Guanjin Peter

Active Member
Joined
May 21, 2008
Messages
429
there wasn't a need to specifcy true or false...that's strange.....

well it works wonders! Thanks!

It'll work for Vb code too?

like:
If Range("b1").Value = "ISNUMBER(B1)"
 
Last edited:

schielrn

Well-known Member
Joined
Apr 4, 2007
Messages
6,941
If it is a number it is presumed true and if it is not then it is presumed false.

In if statements =TRUE and =FALSE are not really needed., but you could put:

=IF(ISNUMBER(B1)=TRUE,TEXT(WEEKDAY(B1),"dddd"),"")

But it is redundant.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,231
Office Version
  1. 365
Platform
  1. Windows
It'll work for Vb code too?

like:
If Range("b1").Value = "ISNUMBER(B1)"
Actually, VBA has an ISDATE function that works even better, as it differentiates numbers from dates (presumably by how they are formatted).

So, in VBA, you can use:
Code:
 If IsDate(Range("B1")) Then
...
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,467
Messages
5,831,802
Members
430,087
Latest member
meagerd

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
Top