VBA If current time is > 5PM then

sdoppke

Well-known Member
Joined
Jun 10, 2010
Messages
647
Hi everyone could someone help me add some code to a script like so:
If current time is > 5PM Then Call MyMacro

thanks a ton in advance.

sd
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
sdoppke,

Try somthing like.....

Code:
If Hour(Now) > 17 Then 
Call YourMacro
End If
 
Upvote 0
sdoppke,


On reflection it should be...

If Hour(Now) > 16

Hope that helps.
 
Upvote 0
Try this:
Code:
currentHour = DatePart("h", Time)
'*** 5:00 PM is hour 17
if currentHour > 17 then 
Call YourMacro
End If
 
Last edited:
Upvote 0
Try this:
Code:
currentHour = DatePart("h", Time)
'*** 5:00 PM is hour 17
if currentHour > 17 then 
Call YourMacro
End If

The question is, what do we mean by >5PM.

Do we mean 6:00PM and later or do we mean 5:00:01 and later?

See the posts by Snakehips.
 
Last edited:
Upvote 0
I realize this is a very old thread but I'm hoping someone sees it and can help. Trying to use a similar code to this but I need the code to pull during a time range--from 5pm until 8AM. I have tried "If ReceivedHour < 08 or > 17 Then" and I keep getting an error. the code works fine with only one time variable. Thanks.
 
Upvote 0
Hi there. Try If ReceivedHour < 08 or ReceivedHour > 17 Then
 
Upvote 0
I realize this is a very old thread but I'm hoping someone sees it and can help. Trying to use a similar code to this but I need the code to pull during a time range--from 5pm until 8AM. I have tried "If ReceivedHour < 08 or > 17 Then" and I keep getting an error. the code works fine with only one time variable. Thanks.

Syntax as per jmacleary ^^^ but 16 not 17

Code:
If ReceivedHour < 8 Or ReceivedHour > 16 Then

Hope that helps.
 
Upvote 0
Doh. Well done snakehips - I read your original correction but then forgot it by the time I wrote my reply - all of 1 minute later!!
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,458
Members
448,899
Latest member
maplemeadows

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