Macro to prevent macros from running until certain time

1nk3d

Board Regular
Joined
May 31, 2016
Messages
51
Longtime lurker, usually can find what I need but this is bothering me.....

I have a report for work, that users pull data from. They click a button for the day of the week, and it pulls data from a report I upload, and gives them data for the previous day. However, many people are pulling it before I have the data (Usually 8:00). I want a macro to add in to my existing macro where if it is before 8:00, it will not allow them to run it.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I found it :) Long day! Appreciate the help

Code:
If (Now() - Int(Now()) < TimeValue("8:30:00")) Then
 
Upvote 0
How would I work this to be before 8:30 or after lets say 17:00? And after 17:00 to display a different message....

I am getting "Compile error: syntax error when I use this code, the above one worked fine...
 
Last edited:
Upvote 0
Put 17:00:00 where my code has 8:30:00.
One branch of the If will call your code, and you can put a MsgBox in the other.
 
Upvote 0
Would I place the second if after the else? So I’d really like it to be between 8:30 and 5. Anytime before or after should display a message


Put 17:00:00 where my code has 8:30:00.
One branch of the If will call your code, and you can put a MsgBox in the other.
 
Upvote 0
Ok I got it! I used your code, and added a second line and added ElseIf with the after time.

Thank you
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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