Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Validating Time e.g. 23:17

Hi,

Just wondering whether i could steal some code from someone. I need to
validate a cell which should contain a valid time. e.g. 12:28 or 23:32 etc?

I've found some regular expression validation on the internet but it doesnt
quite work well enough.

Cheers
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Validating Time e.g. 23:17

Once you have the cell formatted as a date, is it not sufficient to
apply Data Validation to the cells using the 'Date' option in the
'Allow' menu?

You can specify all types of criteria for the date entered.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Validating Time e.g. 23:17

Excel stores time as a fraction of 1 day, 12 hours is .5, 8 hours is .3333.
So any number is valid time to Excel. I assume you mean you want to ensure
that they enter formatted time, but what is valid to you? Is 25:12 valid, or
does it have to be <= 24 hours?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Help me" wrote in message
...
Hi,

Just wondering whether i could steal some code from someone. I need to
validate a cell which should contain a valid time. e.g. 12:28 or 23:32

etc?

I've found some regular expression validation on the internet but it

doesnt
quite work well enough.

Cheers



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Validating Time e.g. 23:17

Hi Guys, Thanks for your response.

Perhaps i should have been more specific. The problem is that the cells
will not specified a Date/Time. it will be set to general (text). So i need
to somehow use regular exp to determine whether the value in the cell is of
the type hh:mm.
cheerx

"Bob Phillips" wrote:

Excel stores time as a fraction of 1 day, 12 hours is .5, 8 hours is .3333.
So any number is valid time to Excel. I assume you mean you want to ensure
that they enter formatted time, but what is valid to you? Is 25:12 valid, or
does it have to be <= 24 hours?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Help me" wrote in message
...
Hi,

Just wondering whether i could steal some code from someone. I need to
validate a cell which should contain a valid time. e.g. 12:28 or 23:32

etc?

I've found some regular expression validation on the internet but it

doesnt
quite work well enough.

Cheers




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Validating Time e.g. 23:17

Hi,
Try this. It assumes times between 00:00 and 23:59 and the format
is hh:mm i.e. contains a colon ":" as delimeter. You could change to a
function if/as required.

HTH

Sub validateTime(TimeStr)

Dim hh As Integer, mm As Integer

If InStr(1, TimeStr, ":") = 3 And Len(TimeStr) = 5 Then
If IsNumeric(Left(TimeStr, InStr(1, TimeStr, ":") - 1)) Then
hh = Left(TimeStr, InStr(1, TimeStr, ":") - 1)
If IsNumeric(Right(TimeStr, Len(TimeStr) - InStr(1, TimeStr, ":")))
Then
mm = Right(TimeStr, Len(TimeStr) - InStr(1, TimeStr, ":"))
If hh = 0 And hh <= 23 Then
If mm = 0 And mm <= 59 Then
Exit Sub
End If
End If
End If
End If
End If

MsgBox "Time " & TimeStr & " is invalid"

End Sub

"Help me" wrote:

Hi Guys, Thanks for your response.

Perhaps i should have been more specific. The problem is that the cells
will not specified a Date/Time. it will be set to general (text). So i need
to somehow use regular exp to determine whether the value in the cell is of
the type hh:mm.
cheerx

"Bob Phillips" wrote:

Excel stores time as a fraction of 1 day, 12 hours is .5, 8 hours is .3333.
So any number is valid time to Excel. I assume you mean you want to ensure
that they enter formatted time, but what is valid to you? Is 25:12 valid, or
does it have to be <= 24 hours?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Help me" wrote in message
...
Hi,

Just wondering whether i could steal some code from someone. I need to
validate a cell which should contain a valid time. e.g. 12:28 or 23:32

etc?

I've found some regular expression validation on the internet but it

doesnt
quite work well enough.

Cheers




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
validating Philashley Excel Discussion (Misc queries) 2 March 13th 08 03:54 PM
Validating times Jack Isaacs New Users to Excel 17 October 6th 07 10:09 AM
validating Ayesha Excel Worksheet Functions 2 April 26th 06 02:56 PM
Validating Sdbenn90 Excel Discussion (Misc queries) 0 March 27th 06 12:05 AM
Validating a Formula Cath[_2_] Excel Programming 2 September 25th 03 08:33 PM


All times are GMT +1. The time now is 03:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"