+ Reply to Thread
Results 1 to 3 of 3

Best logic to return TRUE in VBA if month NAMES are 1 apart?

  1. #1
    Registered User
    Join Date
    07-10-2013
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    77

    Best logic to return TRUE in VBA if month NAMES are 1 apart?

    I want to return TRUE for the following examples:


    Example 1
    Date 1: 7/31/14 Date 2: 8/1/14


    Example 2
    Date 1: 12/31/07 Date 2: 1/1/16 (notice one year is 2007)

    and FALSE for the following example

    Example 1:
    Date 1: 7/31/14 Date 2: 9/1/14


    What is the smartest way to go about this? I know I can use the Month() function and test whether the months are either different by 1 or 11, but that seams like a bad solution

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Best logic to return TRUE in VBA if month NAMES are 1 apart?

    Why would that be a bad solution?

    Please Login or Register  to view this content.
    Please click the * below if this helps

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Best logic to return TRUE in VBA if month NAMES are 1 apart?

    What is the smartest way to go about this? I know I can use the Month() function and test whether the months are either different by 1 or 11, but that seams like a bad solution
    That is the smartest way to go about it and it is a good solution.
    JasperD is on the right track but did not include the Dec/Jan case. Also if x=0 the months are the same, not 1 apart, so I think that case is False.
    Please Login or Register  to view this content.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Count smallest two against a figure in another column and use logic to get true or false
    By MD PERVEZ KHAN in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-20-2015, 06:54 AM
  2. IF formula with multiple Logic Tests and Varying TRUE results
    By andyoungy in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-23-2015, 09:09 AM
  3. Return True if date in cell is between a month and year in drop down comboboxes
    By Julesdude in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-25-2014, 05:18 AM
  4. [SOLVED] logic test showing TRUE when should be FALSE?
    By loopiloo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-23-2013, 01:22 AM
  5. Return True or False if date range falls within current month
    By kieran614 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-17-2013, 12:02 PM
  6. Replies: 3
    Last Post: 07-15-2006, 05:20 AM
  7. [SOLVED] Function to return True/False if all are validated as True by ISNU
    By Tetsuya Oguma in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-15-2006, 06:30 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1