Checking that a Date is a Weekending Day

Dembo

New Member
Joined
Apr 15, 2002
Messages
43
I have a report that requires a user to input a date, this has to be a weekending day. ie. Sunday
How can I write some code to check that the date string is a "Sunday" date?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi

YourVar = UserInputValue

If Not Format(YourVar,"DDDD") = "Sunday" Then
'code to backout here and warn user
End If

Tom
 
Upvote 0
On 2002-04-16 00:07, Dembo wrote:
I have a report that requires a user to input a date, this has to be a weekending day. ie. Sunday
How can I write some code to check that the date string is a "Sunday" date?

=TEXT(A1,"dddd")="Sunday"

where A1 houses a date.

You can even set up data validation on A1 which uses the above formula.
 
Upvote 0
On 2002-04-16 00:07, Dembo wrote:
I have a report that requires a user to input a date, this has to be a weekending day. ie. Sunday
How can I write some code to check that the date string is a "Sunday" date?

=WEEKDAY(A1)=1
 
Upvote 0
You can do this without using VBA. To control the date that is put in cell A1, use Data Validation, select Custom and insert this formula:
=OR(WEEKDAY(A1)=1,WEEKDAY(A1)=7). Unless the date is a Saturday or a Sunday, it will be rejected. I find it helpful to give users an Error Alert telling them what they have done wrong. You might also Format Cell A1 using the Custom Format dddd d mmmm yyy so that the day of the week appears in the cell.
 
Upvote 0
Hi Dembo:
If you are going to use DATA|VALIDAION|SETTINGS|ALLOW|Formula, then you want to use

=WEEKDAY(A1)=1=TRUE ... I need =TRUE in Excel 97

HTH
 
Upvote 0
On 2002-04-20 11:45, Yogi Anand wrote:
Hi Dembo:
If you are going to use DATA|VALIDAION|SETTINGS|ALLOW|Formula, then you want to use

=WEEKDAY(A1)=1=TRUE ... I need =TRUE in Excel 97

HTH

Yogi,

The '=TRUE' portion of your expression above is unnecessary because...

=(condition)=TRUE

...will always return the condition. For example...

=FALSE=TRUE is FALSE
=TRUE=TRUE is TRUE
This message was edited by Mark W. on 2002-04-20 12:04
 
Upvote 0
On 2002-04-20 12:03, Mark W. wrote:
On 2002-04-20 11:45, Yogi Anand wrote:
Hi Dembo:
If you are going to use DATA|VALIDAION|SETTINGS|ALLOW|Formula, then you want to use

=WEEKDAY(A1)=1=TRUE ... I need =TRUE in Excel 97

HTH

Yogi,

The '=TRUE' portion of your expression above is unnecessary because...

=(condition)=TRUE

...will always return the condition. For example...

=FALSE=TRUE is FALSE
=TRUE=TRUE is TRUE
This message was edited by Mark W. on 2002-04-20 12:04

Thanks Mark!
For some reason, when I used
=WEEKDAY(A1)=1 first, it did not work for me, and then when I did force it with
=WEEKDAY(A1)=1=TRUE ... it did! that's why I had flagged it to see if someone else had the same isssue. It looks like when it did not work for me first, I must have made some mistake!
Thanks again for catching that and the explanation of the logic behind it.

Regards!

Yogi Anand
 
Upvote 0

Forum statistics

Threads
1,213,507
Messages
6,114,029
Members
448,543
Latest member
MartinLarkin

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