VBA with ISDATE

VeryForgetful

Board Regular
Joined
Mar 1, 2015
Messages
242
Hi,

Hoping someone can help me with some vba please.

I'm looking to test a range of A2:A to see if a valid date has been entered.

The data is being pasted from another file and if any of the cells in range does not equal a valid date then Exit Sub, else code carries on running. I've looked into the ISDATE function but not sure how to apply it to a range. I also need the code to ignore any blanks in the range.


My code runs on a worksheet change event if target.column=1 which executes on paste.
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
what would you like to happen if the entry isn't a valid date?
code would go something like

Dim c As Range, rng
Set rng = Range("a1:a31")
For Each c In rng
MsgBox c
If IsDate(c) = False Then
c.Offset(0, 1) = "not a valid date"
End If
Next c
 
Last edited:
Upvote 0
Thanks Steve,

if any of the cells contain something that isn't valid then I need the sub to just exit. I don't need any prompt or anything like that.

Blanks are ok so would need the code to ignore those rows.
 
Upvote 0

Forum statistics

Threads
1,225,328
Messages
6,184,306
Members
453,227
Latest member
Slainte

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