Weekday () function VBA - baffled!

chrisd282

New Member
Joined
Mar 14, 2011
Messages
2
Hi everyone, I'm hoping that someone can help me with a problem I've got.

I am trying to get a message box to appear if a check in date is a Thursday, Friday, Saturday or a Sunday, and have set up an IF fuction in VBA, however it never works.

Code:
'declarations
Dim counter As Integer
Dim checkindate As Date
counter = Cells(1, 16).Value
checkindate = Cells(counter, 4).Value
 
If Weekday(checkindate) = 1 Then daytext1 = "Sunday"
If Weekday(checkindate) = 2 Then daytext1 = "Monday"
If Weekday(checkindate) = 3 Then daytext1 = "Tuesday"
If Weekday(checkindate) = 4 Then daytext1 = "Wednesday"
If Weekday(checkindate) = 5 Then daytext1 = "Thursday"
If Weekday(checkindate) = 6 Then daytext1 = "Friday"
If Weekday(checkindate) = 7 Then daytext1 = "Saturday"
 
If Weekday(checkindate) = 1 Or 5 Or 6 Or 7 Then
MsgBox (daytext1)
Else
MsgBox ("seems to work")
Exit Sub
End If

However, if a date, for example the 15th March (Tuesday) is the checkindate, the message box always appear. This should only appear if the checkindate is Sunday, Thursday, Friday or Saturday.

HELP please :)

Many thanks in advance.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi there,

You need to retype Weekday(checkindate) = x after every OR:

Code:
    If Weekday(checkindate) = 1 Or Weekday(checkindate) = 5 Or Weekday(checkindate) = 6 Or Weekday(checkindate) = 7 Then
        MsgBox (daytext1)
    Else
        MsgBox ("seems to work")
        Exit Sub
    End If
 
Upvote 0
Another way:

Code:
Sub y()
    Dim counter     As Integer
    Dim checkindate As Date
 
    counter = Range("P1").Value
    checkindate = Cells(counter, "D").Value
 
    If Weekday(checkindate, vbMonday) >= 4 Then
       MsgBox Format(checkindate, "dddd")
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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