How to validate Time in a Data Entry Form?

uknwtheusername

New Member
Joined
Apr 12, 2012
Messages
7
Hi everyone,

I'm making a data entry form for a user, and one of the fields is in a time format (mm:ss). Is there any way that I can validate that field in "cmdOK_Click()" so that when the user clicks "ok" on the data entry form, if they haven't entered a date a msgbox comes up.

I tried IsNumeric with an If function but to no prevail.

Thank you for your help! :)
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
you could try this:

Code:
if Range("A1").text like ##:##

~Mathchick
Thanks for your reply!

I'm getting an error message when I try to plug that in, here's the code so you can check it out and see what's up:

If Range(txtDuration).text like ##:## End If

I'm getting a message saying: "Compile error. Expected: expression" and it highlights the '#' tags.

I assumed that 'Range("A1")' from your example was equal to the field I want to validate (btw, if you need to know, the duration is entered into the H:H column of my worksheet, but not necessarily at H:1)

Thanks for your help, and please help me out :D
 
Upvote 0
whoops:

Code:
if Range("A1").text like "##:##"

that work?
~Mathchick
I messed around with what you gave me and I ended up with this:

If txtDuration.Value = Text Then
txtDuration.Value = "##:##"
End If

It seems to be working fine, so thanks for your help man, cheers!
 
Upvote 0

Forum statistics

Threads
1,215,328
Messages
6,124,299
Members
449,149
Latest member
mwdbActuary

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