What "format" is your time (TimeValue)?
Where are you getting it?

Keep in mind that in an Excel worksheet,
a cell may LOOK like time but it really isn't.
It is a numeric value that represents a fraction of a day
for instance:
What you SEE as 8:00:27
is actually .3336458333
Or it COULD be 40052.3336458333
which is TODAY at 8:00:27 (8/27/2009 8:00:27)

Also  I wouldn't recommend using "TimeValue" as the
name of a variable, since it is also a FUNCTION.

The trick is that you ahve to get the two things you're
comparing into the same 'units'.

You could try:
Sub chktime()
    Dim tval, tval2
    tval = Range("A1").Value
    tval2 = TimeValue("08:00:30")
    
    If (tval < tval2) Then
        Debug.Print Format(tval, "h:mm:ss AMPM") & " < " & tval2
    Else
        Debug.Print Format(tval, "h:mm:ss AMPM") & " > " & tval2
    End If
End Sub

Now, if the field also has the DATE as well as time,
then I'd recommend looking at the DateDiff function.

hope this helps.

paul




________________________________
From: Jack <[email protected]>
To: MS EXCEL AND VBA MACROS <[email protected]>
Sent: Thursday, August 27, 2009 7:50:57 AM
Subject: $$Excel-Macros$$ Application TimeValue


i need some vb to check if the time is greater than  eg IF Application
TimeValue > ("08:00:30") Then
activeworkbook.close

Any ideas

Many thanks


--~--~---------~--~----~------------~-------~--~----~
----------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to [email protected]
If you find any spam message in the group, please send an email to:
Ayush Jain  @ [email protected] or
Ashish Jain @ [email protected]
<><><><><><><><><><><><><><><><><><><><><><>
HELP US GROW !!

We reach over 5,200 subscribers worldwide and receive many nice notes about the 
learning and support from the group. Our goal is to have 10,000 subscribers by 
the end of 2009. Let friends and co-workers know they can subscribe to group at 
http://groups.google.com/group/excel-macros/subscribe
-~----------~----~----~----~------~----~------~--~---

Reply via email to