![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 40
|
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? |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi
YourVar = UserInputValue If Not Format(YourVar,"DDDD") = "Sunday" Then 'code to backout here and warn user End If Tom |
|
|
|
|
|
#3 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
|
Quote:
where A1 houses a date. You can even set up data validation on A1 which uses the above formula. |
|
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
|
Quote:
|
|
|
|
|
|
|
#5 |
|
New Member
Join Date: Apr 2002
Posts: 40
|
Thanks guys!
|
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Apr 2002
Location: Wivenhoe, England
Posts: 877
|
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. |
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,452
|
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
__________________
Regards! Yogi Anand, D.Eng, P.E. Energy Efficient Building Network LLC www.energyefficientbuild.com |
|
|
|
|
|
#8 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
|
Quote:
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 ] |
|
|
|
|
|
|
#9 | ||
|
MrExcel MVP
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,452
|
Quote:
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 |
||
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|