pretty complex vba

  Josquius 12:45 24 Mar 05

What have I done wrong here? I am trying to get excel to recognise times and only accept correct 24 hour clock times though I don't know how to split it into the 3 parts needed.
What I have is (its part of bigger code hence no dims et all)

time = InputBox("Enter the time")
If time = "" Then End
valid = True
For count = 1 To count = 2 Step 1
char = Mid(time, count, 1)
If (char "0" Or char > "9") Then valid = False
Next count
For count = 3 To count = 3 Step 2
char = Mid(time, count, 1)
If (char > ".") Then valid = False
For count = 4 To count = 5 Step 3
char = Mid(time, count, 1)
If (char "0" Or char > "9") Then valid = False

I get some kind of erro saying for is already in use or something along those lines.

  Yoda Knight 13:02 24 Mar 05

Not getting "For without Next" error ?

  VoG II 13:05 24 Mar 05

For count = 3 To count = 3 Step 2

for example does not make a lot of sense.

Why not:

Sub GetATime()

Dim TheString As String

Dim TheTime As Double

TheString = Application.InputBox("Enter A Time")

If IsDate(TheString) Then

TheTime = TimeValue(TheString)


MsgBox "Invalid date"

End If

End Sub

  Josquius 13:13 24 Mar 05

I have for 3 to 3 as just having for 3 brought back a error.
What is a double, I'm not familiar with this. 2 numeric characters?

  VoG II 13:20 24 Mar 05

It doesn't have to be a double actually, single would do. That's not the point. Why write all that code when you can use the inbuilt function IsDate() to validate the entered time?

  Josquius 13:42 24 Mar 05

Arg just noticed my lines haven't shown up in my pasted in version...
I don't know about the isdate() function. Does it work for times and not just dates?

  Josquius 13:48 24 Mar 05

I'm not entirely sure how it works but it seems it does.

  Josquius 14:51 24 Mar 05

Actually no not resolved, a minor problem- it allows you to put 3 figures after the decimal (15.003 is accepted) though past 3 and it comes up with the error, how do you bring the 3 to just accepting 2?

  Yoda Knight 15:20 24 Mar 05

check the LEN of TheString ?

  VoG II 15:53 24 Mar 05


TheString = Application.InputBox("Enter A Time")

TheString = Left(TheString, 5)


This thread is now locked and can not be replied to.

Nintendo Switch review: Hands-on with the intuitive modular console and its disappointing games…

1995-2015: How technology has changed the world in 20 years

This abstract video touches on division in our technologic world

Best alternatives to iTunes for Mac | Best music players for macOS: Free your music from the…