Consulting

Results 1 to 3 of 3

Thread: Match 1 date against 3 col

  1. #1
    VBAX Regular
    Joined
    Dec 2011
    Posts
    14
    Location

    Match 1 date against 3 col

    I have a Date in Cell A1 and I need to compare it against dates in Cell C1,D1,E1

    If cel A1 is not the first day of the month then "Not Aligned"

    If Cel A1 is the first of the month but the date in either C1,D1,E1 does not match then "Not Aligned"

    IF If Cel A1 is the first of the month and the date in either C1,D1,E1IS the matching first day of the Month of A1 then "Aligned"

    Any thoughts

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    =IF(AND(DAY(A1)=1,NOT(ISNA(MATCH(A1,C1:E1)))),"Aligned","Not Aligned")
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    I believe that these are the rules

    Rule 1

    A1 = 1/4/2017 -- Not aligned since not first day of month


    Rule2

    A1 = 1/1/2017
    C1 = 1/2/2017, D1 = 2/3/2017, E1 = 3/4/2017 -- not aligned since A1 is first of month but A1 not = any of C1, D1, E1


    Rule3

    A1 = 1/1/2017
    C1 = 1/2/2017, D1 = 2/3/2017, E1 = 1/1/2017 -- aligned since A1 = E1



    I'm not sure that Rule3 is needed since if all of C1, D1, and E1 <> A1 fails, then at least one of the 3 must = A1


    Option Explicit
    
    Function Aligned(Date1 As Date, Date2 As Date, Date3 As Date, Date4 As Date) As String
        Aligned = "Not Aligned"
        
        If Day(Date1) <> 1 Then Exit Function
        
        If Date1 <> Date2 And Date1 <> Date2 And Date1 <> Date4 Then Exit Function
        
        Aligned = "Aligned"
    End Function
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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