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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
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

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,155
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

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
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

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,155
@ 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,190,677
Messages
5,982,216
Members
439,769
Latest member
trungminh2802

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
Top