checking if time greater

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Checking if time is greater or less than a specific time

Checking if time is greater or less than a specific time

resolvedResolved · Low Priority · Version 2010

Checking if time is greater or less than a specific time

Hello,
Please could you tell me why the following statement does not work? I have tried using "ActiveCell.Offset(0, 3).Value > 0.5" instead of stating the actual time as I would like everything past midday but this does not work either.

Sub WedsPM()

Range("I2").Select
Do Until ActiveCell = ""
If ActiveCell.Value = "Wednesday" And (ActiveCell.Offset(0, 3).Value > TimeValue("12:00:00") Or ActiveCell.Offset(0, 2).Value > TimeValue("12:00:00")) Then
ActiveCell.EntireRow.Interior.ColorIndex = 43
End If

ActiveCell.Offset(1, 0).Select
Loop

End Sub

RE: Checking if time is greater or less than a specific time

Hi Natasha,

Thank you for the forum question.

The code works fine. You may have a problem with the time you are testing.

If Excel does not recognise your time as time the code will not work.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Thu 21 Dec 2017: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Adding a comment to a formula

1. At the end of the formula, add a + (plus) sign.
2. Type the letter N, and in parentheses, type your comment in quotation marks.

eg.

=CurrentAssets / CurrentLiabilities+ N("The formula returns Current Ratio")

View all Excel hints and tips


Server loaded in 0.07 secs.