Comparing Time

ramedju

New Member
Joined
Jan 27, 2016
Messages
10
Hi guys!
Anyone know how to compare the input time and current time in excel VBA ?

This is my code Snippet
Code:
time = "11:59:59 AM"
If Format(TimeValue(Now)) <= time Then
    test = "Good morning!"
Else
    test = "Good Afternoon!"
End If

This always returns 'Good Afternoon' and it is my problem. Is there's something lacking or anything?

Any help is highly appreciated!

Thank you so much!
 
Try this
Code:
If TimeValue(Now) <= TimeValue("11:59:59 AM") Then
    test1 = "Good morning!"
Else
    test1 = "Good Afternoon!"
End If
 
Upvote 0
Hi Akuini, It seems that it is also that the code you've given is just as the same as I have asked. But thanks for the effort :)
 
Upvote 0
Hi everyone!
This is my code to solve my problem :)
Code:
   If TimeValue(Now) <= time Then
        test = "Good morning!"
    Else
        test = "Good Afternoon!"
    End If
Thanks!
 
Upvote 0

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