+ Reply to Thread
Results 1 to 11 of 11

Month Identification

  1. #1
    Forum Contributor
    Join Date
    01-04-2011
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2003
    Posts
    129

    Month Identification

    Hello All,

    This is very similar to another question I asked previously, but with some differences.

    I have a column of data with a date in the format:

    Jan 11, 2011
    Feb 10, 2011
    Dec 5, 2010
    Nov 12, 2010
    Mar 5, 2011

    Etc

    I need to identify the month and compare it to the current month So the output would be

    Jan 11, 2011 -> Past Due
    Feb 10, 2011 -> Current Month
    Dec 5, 2010 -> Past Due
    Nov 12, 2010 -> Past Due
    Mar 5, 2011 -> CM+1

    I think the code would look something like this

    Please Login or Register  to view this content.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Month Identification

    You could adjust the dates and apply a DateDiff calculation, or you could convert dates to numeric yymm value for comparison in your Select Case

    Below uses an alternative approach - utilising Evaluate to update all entries simultaneously by applying the same yymm logic outlined above

    Please Login or Register  to view this content.
    modify sheet reference as nec.

  3. #3
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Month Identification

    Perhaps this formula also. If the date is in cell 'A1'
    Please Login or Register  to view this content.
    regards

    johnjohns

    When you are not sure where to go, every road takes you there!

  4. #4
    Forum Contributor
    Join Date
    01-04-2011
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2003
    Posts
    129

    Re: Month Identification

    DonkeyOte,

    I had to modify just a little the last 2 "_" underscores the program didn't like, so I removed those and it worked perfect. Not sure what the purpose of those are, but removing them didn't seem to alter the functionality.

    In your code you have "-9.99E+307,0,1,2,3", what does this mean. As I am trying to learn as much as I can I want to make sure that I can duplicate this again if necessary. Thank you.

    Johnjohns,

    There was a missing ")" according to my program and I couldn't figure out where it was. I liked it because it was condense to one line, but ultimately I couldn't get it to work.

    Thank you both for your help.

    Kelly

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Month Identification

    Please Login or Register  to view this content.
    the above will be lower than any number generated by the date vs date calculation: yymm - yymm

    the integer result of the yymm - yymm calculation is applied to the lookup_vector:

    Please Login or Register  to view this content.
    and the associated value from the result vector is returned

    Please Login or Register  to view this content.
    so where result is:

    < 0 ..... Past Due
    0 .... Current Month
    1 .... CM+1
    2 .... CM+2
    3+ .... Beyond

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Month Identification

    edit: just realised that this approach is fatally flawed - oh dear - not a good day!

    yymm - yymm is not valid for this type of calculation given year cross overs and the need to separate 1 | 2 and 3+

    Consider today is Dec 10th 2011 and the date being compared is 4th Dec 2012:

    1201-1112

    would result in "Beyond" rather than "CM+1"

    I will post back shortly with a solution that actually works

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Month Identification

    In light of above...

    Select Case approach:

    Please Login or Register  to view this content.
    Evaluate route:

    Please Login or Register  to view this content.
    Apologies for confusion caused - I should have thought that through.
    Last edited by DonkeyOte; 02-03-2011 at 03:56 AM. Reason: missing adjustment to Date

  8. #8
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Month Identification

    Hi Kelly,

    This is what I did. See the attachment
    Attached Files Attached Files
    Last edited by johnjohns; 02-03-2011 at 01:49 AM.

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Month Identification

    @johnjohns, that approach would fail for the exact same reasons as my initial suggestion - outlined in post # 6
    ie were TODAY() say 10th Dec 2010 your results for Jan 2011 dates would be incorrect

    Formula wise - alternative to that suggested in evaluate:

    Please Login or Register  to view this content.
    or per Evaluate

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Month Identification

    I tried with 10th Dec 2010 and you are right DonkeyOte. Sorry for the confusion.

  11. #11
    Forum Contributor
    Join Date
    01-04-2011
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2003
    Posts
    129

    Re: Month Identification

    Thank you both. I really appreciate the help and the follow up. I would never have realized it till it bit me towards the middle or Q4.

    If you guys have time I would appreciate help with a VLOOKUP issue that I have been having. I have posted the code and a sample sheet in a different posting titled "Dynamic VLOOKUP".

    Thank you both again.

    Kelly

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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