VBA if Today is Monday then code, if Thursday then code

stoutbn

Board Regular
Joined
Aug 3, 2016
Messages
52
For some reason, I cannot get any forums' posts to work in my code. Keep getting errors. But as my Title explains, I simply want to know if the day today is Monday, then to run a certain code, if it is Thursday, then to run a different line of code. Have tried using the weekday function but have had no luck.

Please dumb down any responses as I am fairly new to VBA. Thank you!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
VBA?
Code:
Sub tester()
If Format(Now(), "DDD") = "MON" Then
'run monday code

endif
If Format(Now(), "DDD") = "Thu" Then
'run thursday code

endif

End Sub
 
Upvote 0
Just another take:

Rich (BB code):
Sub example()
  Select Case Weekday(Date, vbMonday)
  Case 1
    MsgBox "Today is Monday; we'll run that code"
  Case 2
    MsgBox "Today is Tuesday; we'll run that code"
  Case 3
    'and so on...
  End Select
End Sub
 
Last edited:
Upvote 0
I want to learn CASE a bit more, how does it know that CASE 2 is Tuesday? Does the Select Case(Date, vbMonday) assume case 2 is VbTuesday in sequence?
 
Upvote 0
@ Roderick_E:

Greetings Roderick,

Weekday() returns a variant/Integer and in this case, I set Monday as day 1 of the week. So yes, if it is Tuesday, Weekday() will return 2 and so on.

Hope that helps,

Mark
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,007
Members
448,935
Latest member
ijat

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