+ Reply to Thread
Results 1 to 8 of 8

Recognize single digit number as month for subtraction

  1. #1
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Recognize single digit number as month for subtraction

    Hello,

    I have data coming out of a system where the month number and year are coming out in two separate columns. Example: One cell has a 3 and the other a 16. For calculation purposes there is another field that shows the number 4. 4 represents the number of months to count back from 3 in order to grab a CPI index to calculate CPI increases. The issue I am having is if I subtract 4 from 3 I get negative 1. I need to take 4 away from three to get 11 (November). So that the calculation will grab the CPI index that was reported 4 months before the 3(March). any suggestions? If it were farther along in the year it would work fine. It is when it crosses years that it becomes an issue and the fields are not coming over in a date format where the subtraction would work.

    Thanks in Advance!

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Recognize single digit number as month for subtraction

    Try

    =MONTH(EDATE(DATE(2017,G1,1),-I1))

    G1 = given month # (3)
    I1 = number to subtract from month number (4)

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Recognize single digit number as month for subtraction

    Let's say your month is in B5
    =MOD(B5-4,12)+1

    Using Jon's cells below
    G1 = given month # (3)
    I1 = number to subtract from month number (4)

    =MOD(G1-I1,12)+1
    Last edited by ChemistB; 07-20-2017 at 04:02 PM.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Recognize single digit number as month for subtraction

    Thanks. that formula worked very nicely. there are other fields to where I can get the 2017 to be formula driven too I suppose.

  5. #5
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Recognize single digit number as month for subtraction

    ChemistB...Your formula works as well but without the +1 in it. The plus 1 makes the number 12 and I need it to be 11. Removing the plus 1 gets me to 11. Both formulas seem to work nicely.

  6. #6
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Recognize single digit number as month for subtraction

    It doesn't need to be specific to any year, because you're only interested in the month number.

    Realistically the 2017 could just be a 1. But you could only subtract up to 2 years worth of months.
    I just put 2017 to avoid confusion.
    Last edited by Jonmo1; 07-20-2017 at 04:11 PM.

  7. #7
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Recognize single digit number as month for subtraction

    awesome. thanks again to you both.

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Recognize single digit number as month for subtraction

    Chemist's formula needs the plus 1 because month 4 - 4 would equal 0, there is no such month as 0.

    I think that should be
    =MOD(B5-5,12)+1

+ 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. Color a single digit in a mult-digit number cell
    By Phyllis in forum Excel General
    Replies: 8
    Last Post: 09-30-2022, 04:22 PM
  2. [SOLVED] LOTTERY FILTER#4, Find if 1 Digit Sum of 2 Digit or 3 Digit, Single Cell w/ dash
    By david gonzalez in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-08-2014, 12:57 AM
  3. [SOLVED] Single cell - double digit subtraction???
    By greenfox74 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-09-2012, 12:30 AM
  4. Replies: 4
    Last Post: 09-16-2012, 10:26 AM
  5. Delete the entire column that has single digit number - Part-2
    By plasma33 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2012, 01:44 AM
  6. [SOLVED] Delete the entire rows that has single digit number
    By plasma33 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2012, 08:17 AM
  7. Return name of month based on single digit number
    By fredthehead in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-09-2008, 04:46 PM
  8. [SOLVED] how to convert single digit to month name
    By cygnus in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-27-2006, 05:40 PM

Tags for this Thread

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