Checking that a Date is a Weekending Day
Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 9 of 9

Thread: Checking that a Date is a Weekending Day

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    43
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    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. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi

    YourVar = UserInputValue

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

    Tom

  3. #3
    MrExcel MVP Aladin Akyurek's Avatar
    Join Date
    Feb 2002
    Location
    The Hague, NL
    Posts
    81,846
    Post Thanks / Like
    Mentioned
    12 Post(s)
    Tagged
    1 Thread(s)

    Default

    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.

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Austin, Texas USA
    Posts
    11,654
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  5. #5
    New Member
    Join Date
    Apr 2002
    Posts
    43
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks guys!

  6. #6
    Board Regular
    Join Date
    Apr 2002
    Location
    Wivenhoe, England
    Posts
    912
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #7
    MrExcel MVP
    Join Date
    Mar 2002
    Location
    Michigan USA
    Posts
    11,454
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #8
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Austin, Texas USA
    Posts
    11,654
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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 ]

  9. #9
    MrExcel MVP
    Join Date
    Mar 2002
    Location
    Michigan USA
    Posts
    11,454
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    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

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com