Run Different Marcos based on Day of the Week

ardanni90

New Member
Joined
Dec 2, 2015
Messages
16
Hello All,

So I am trying to run 3 different macros based on the day of the week. The code I found worked when I just used one day but when I entered the same code in for all 5 days, I keep getting the error: Block If without End If.

Here is the code I have so far:

Sub Datetest()

Dim sDate As String
sDate = Format(Date, "ddd")
If sDate = "Mon" Then
Run "Monday"
Else
If sDate = "Tue" Then
Run "Tuesday"
Else
If sDate = "Wed" Then
Run "Macro1"
Else
If sDate = "Thu" Then
Run "Macro1"
Else
If sDate = "Fri" Then
Run "Macro1"
End If
End If

End Sub

Any help would be much appreciated.

Thanks!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try

Code:
Select Case sDate
    Case "Mon": Application.Run "Monday"
    Case "Tue": Application.Run "Tuesday"
    Case "Wed", "Thu", "Fri": Application.Run "Macro1"
End Select
 
Upvote 0
Maybe
Code:
Sub Datetest()
Dim sDate As String
sDate = Format(Date, "ddd")
If sDate = "Mon" Then
Run "Monday"
ElseIf sDate = "Tue" Then Run "Tuesday"
ElseIf sDate = "Wed" Or sDate = "Thur" Or sDate = "Fri" Then Run "Macro1"
End If
End Sub
 
Upvote 0
So I dont get the error anymore but when it gets to the the "Wed" line, it just skips past that and does not run "Marco1"

Do I still need to Dim sDate As String?
 
Upvote 0
Is Macro1 actually called "Macro1"....if the syntax is incorrect it won't fire the Macro
AND a slight typo for Thursday
Code:
Sub Datetest()
Dim sDate As String
sDate = Format(Date, "ddd")
If sDate = "Mon" Then
Run "Monday"
ElseIf sDate = "Tue" Then Run "Tuesday"
ElseIf sDate = "Wed" Or sDate = "Thu" Or sDate = "Fri" Then Macro1
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,111
Members
452,302
Latest member
TaMere

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