+ Reply to Thread
Results 1 to 5 of 5

Avoiding massive nested if statements - choose different column depending on month

  1. #1
    Registered User
    Join Date
    09-16-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    16

    Avoiding massive nested if statements - choose different column depending on month

    Hi.

    I have a summary sheet on a financial spreadsheet. I am trying to avoid complicated nested if statements which are prone to error and difficult to update.

    What I have on the summary tab is, for example, 6 different columns which index match/lookup data from another sheet. The other sheet contains in column A, a unique identifier for all the production locations of the business. There are then a series of columns, each of which is for a different product and month. For example, column b-m are volume of Product 1, for months Jan-Feb in 2012. The next 12 columns would be for Product 2 volume, for months Jan-Feb. My summary sheet then index/matches based on the unique identifier. I update the summary tab each month.

    What I would ideally like to do, is to change just one cell on the summary tab, which would say "August" or some indicator of the month that we're in (could be a number instead). This will then go and grab the appropriate column on the other tab.

    Any ideas how to do this by avoiding a massively complicated if statement?

    See example:

    Ideally I'd like to be able to just change that highlighted cell to, say, May, and the formula changes to index(Detail!F:F...etc.) instead of having to do this manually/with a massive if statement (for many different products).
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-16-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Avoiding massive nested if statements - choose different column depending on month

    Looks like I've got you guys stumped?

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Avoiding massive nested if statements - choose different column depending on month

    i think i have what you need. i created 4 named ranges (prod a vol, prod a mth, prod b vol, prod b mth), and used them for the index/match. i also added a criteria for your product range too (A/B)

    if you need to increase the ranges, just go into name manager and increase them that way

    let me know how this works out for you?
    Attached Files Attached Files
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    09-16-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Avoiding massive nested if statements - choose different column depending on month

    Hi. Looks good. But how do I omit the product choice aspect? The thing is, I am going to display many products in columns next to each other, so I don't really need that flexibility within a cell. So, really, I think I just need that extra match bit, to match the month up. So how do I do that?

    Alternatively, how do I expand the formula to incorporate n products? I would probably not want this, though, because I prefer less complicated formula that I can get my head arou

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Avoiding massive nested if statements - choose different column depending on month

    change the formula to =INDEX(Product_A_Vol,MATCH(A4,Detail!$A$3:$A$13,0)+1,MATCH($B$1,Prod_A_Mth,0)) (i was trying to avoid hard-coding in the formula)

    to add new products, just add 2 new named ranges, 1 for the data table, and 1 for the months, and then hard-code the product name into the formula

    to do this thru a formula will get messy, the easiest way would be to have a list of your name ranges off to the side and use a vlookup inside that formula.

    if you want to go that route, let me know and i will try and put something together for you. else you can stick with the hard-coding, and copy/paste for new products

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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