run a macro at condition

dikken20

Board Regular
Joined
Feb 25, 2009
Messages
130
Office Version
  1. 2010
Platform
  1. Windows
Hi,

I have a macro.
I want it to be run automatically at a specific time, but not every day but only on days that are not holidays.

Additional available values I have on my sheet that may help:

1. I have a cell in my sheet that indicates me whether today is an holiday or not (If today is a holiday then this cell's value turn to "Holiday", if not, its value is "WorkingDay").

2. I have a cell that tells me the exact time each second automatically.


Any ideas how to make this happened ?

Thank you in advance!
Dikken.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
The macro is pretty simple:

It copies column D into column E, then copies column C in to column D, then B into C.

I tried triggeting by Ontime but it didn't work...

Therefore, there must be a simple way to do this, I just don't know how and need help on this :)
 
Upvote 0
If you do a web search for something like; Excel VBA Application.OnTime, you will find several step-by-step guides on how to set up a macro to run at a specific time every day. Here's one: How to Run a Macro at a Set Time

In your daily run macro, you could have something like this to have it "do something" only on Working Days.

Code:
Sub Daily_Macro()
    If Sheets("Sheet1").Range("A1").Value = "WorkingDay" Then
        [COLOR="Green"]'Do somthing here or call another macro[/COLOR]
    End If
End Sub
 
Last edited:
Upvote 0
Thanks for your replies guys,

Arcticwarrio,
The file is opened all the time. Since I'm away from my PC very often, I want this to be done automatically without my need to open it or do something else. plus, each time the files been open - I need to enable the macro.


AlphaFrog,
I've done something like your suggested a while ago after reading bout that on the net. It really worked but only for the same day I wrote it, the day after... it stopped. This is the reason I asked bout some other possible solution.
 
Upvote 0
It really worked but only for the same day I wrote it, the day after... it stopped. This is the reason I asked bout some other possible solution.

The daily macro needs to to initiate the next OnTime event so it will run again the next day.

Code:
Sub Daily_Macro()

    If Sheets("Sheet1").Range("A1").Value = "Holiday" Then
        'Do somthing here or call another macro
    End If
    
[COLOR="Red"]   Application.OnTime TimeValue("15:00:00"), "Daily_Macro"[/COLOR]
    
End Sub

Are you doing something like that in you actual macro?
 
Last edited:
Upvote 0
ArcticwarrioHow do I do that ?


AlphaFrogI think that now I've got the reason it ran only one time (and tell me if I'm wrong), because I need to initiate it each time after it run on that time, right ?
Well, I'll do what you've offered me, but I remember that after it didn't run that day (after the day it did) I "F5" it, shouldn't the method be initated then ?


Thanks again.

Edited: Hmm,.. did you edited your answer ? I can't see the entire code you wrote before.. :(
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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