Run Macro IF() Today...?

ilcaa

Well-known Member
Joined
May 25, 2005
Messages
751
Office Version
  1. 365
Platform
  1. Windows
Trying to word this correctly within my "This Workbook"..

Private Sub Workbook_Open()

Worksheet("symbol list").Select
With Selection IF(TODAY()>K1,Application.Run "Add_Days_Ranking","")

End Sub

'K1 being a DATE..either yesterdays,todays, Fridays..
-------------

Basically what I need is for the Macro to run if its the next day (run only 1time), also exclude SAT/SUNS from running this Macro...thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Code:
Private Sub Workbook_Open()
Select Case Weekday(Date)
    Case 1, 7
        'do nothing -- weekend
    Case Else
        Select Case DateDiff("d", Sheets("sheet1").Cells(1, 1), Date)
            Case 1
                Call Add_Days_Ranking
        End Select
End Select
End Sub
 
Last edited:
Upvote 0
thanks but im getting some errors and cant seem to pinpoint it it occurs on this line
Select Case DateDiff("d", Sheets("sheet1").Cells(1, 1), Date)

* What is "d" referring to?
* i changed the "sheet1" to my sheets name, "Symbol List" (i assume I was suppose to)
* the ending, Cells(1,1) whats that reference...should I change that?

thanks for the help...

Private Sub Workbook_Open()
Select Case Weekday(Date)
Case 1, 7
'do nothing -- weekend
Case Else
Select Case DateDiff("d", Sheets("sheet1").Cells(1, 1), Date)
Case 1
Call Add_Days_Ranking
End Select
End Select
End Sub
 
Upvote 0
sorry, I failed to alter the cells reference -- should read Cells(1,11), try that.

"d" is used in a datediff function -- the datediff determines difference between 2 dates (in your case today and your value K1) -- the "d" tells Excel to return that difference in terms of days as opposed to months ("m") etc...

Cells(row,column) refers to a cell in R1C1 fashion -- eg Cells(1,1) = A1, Cells(1,2) = B1 etc... these are the equivalents of Range("A1"), Range("B1") etc but Cells(x,y) method is more prevalent in VBA given it's greater flexibility.
 
Upvote 0
actually figured it out...thanks

works nicely...
 
Upvote 0
Hello world!, Not intending to hijack somebody's thread, but how would I create a range of dates that extends thru the whole month, say: A2 6/26/08, A3 6/27/08, A4 6/28/08 and so on until month's end.

Regards!

Sumeluar
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

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