+ Reply to Thread
Results 1 to 10 of 10

How to use dynamic variables in an Index & Match function?

  1. #1
    Registered User
    Join Date
    10-27-2017
    Location
    Perth
    MS-Off Ver
    O365
    Posts
    2

    How to use dynamic variables in an Index & Match function?

    Hey Guys,

    First time poster so i apologise if i'm doing this incorrectly/breaking any rules.

    Basically, i've got the below code and it works just fine but it's not the most elegant solution and i was wondering if any of you had any bright ideas on how to tidy this up a little?

    Basically, i have three columns, A & B are data validation lists. B is a dynamic list depending on what is next to it in A. The code below sits in column C.

    On another sheet i have a bunch of 2-column tables. List A displays all of the tables and list B will then list the rows entries of one of those two columns of the table you select with list A. The code below will then display whatever is in the second column (of the table and row you select with list A and List B).

    =IFERROR(INDEX((IF(T15='Business Units'!B$2,CorpBU,(IF(T15='Business Units'!B$3,DMSBU,(IF(T15='Business Units'!B$4,ESBU,(IF(T15='Business Units'!B$5,ESSBU,(IF(T15='Business Units'!B$6,JOBBU,(IF(T15='Business Units'!B$7,NDISBU,(IF(T15='Business Units'!B$8,NPABU,(IF(T15='Business Units'!B$9,OHBU,(IF(T15='Business Units'!B$10,PEBU,(IF(T15='Business Units'!B$11,PHaMsBU,(IF(T15='Business Units'!B$12,RASBU,(IF(T15='Business Units'!B$13,WCBU,(IF(T15='Business Units'!B$14,WFDBU,(IF(T15='Business Units'!B$15,YEPBU,"")))))))))))))))))))))))))))),MATCH($P15,(IF(T15='Business Units'!B$2,Corp,(IF(T15='Business Units'!B$3,DMS,(IF(T15='Business Units'!B$4,ES,(IF(T15='Business Units'!B$5,ESS,(IF(T15='Business Units'!B$6,JOB,(IF(T15='Business Units'!B$7,NDIS,IF(T15='Business Units'!B$8,NPA,(IF(T15='Business Units'!B$9,OH,(IF(T15='Business Units'!B$10,PE,(IF(T15='Business Units'!B$11,PHaMs,(IF(T15='Business Units'!B$12,RAS,(IF(T15='Business Units'!B$13,WC,(IF(T15='Business Units'!B$14,WFD,(IF(T15='Business Units'!B$15,YEP,""))))))))))))))))))))))))))),0),1),"")

    Note: in the above code, entries that have the suffix BU (i.e CorpBU) are a table and anything that doesn't have 'BU' (i.e. Corp) is a named range. These named ranges are a column in each of the 2-column tables. For example; The 2-column table called 'CorpBU' has two columns, One called 'GL code' and one called 'Finance Code'. The named Range 'Corp' refers to the 'Finance Code' column of 'CorpBU'. These tables are business units.

    I tried playing around with index & match but i found i couldn't figure out a way to dynamically change the array variable.

    For example what i would have liked is =index(~dynamic variable from List A/a business unit table name~,Match(cell referencing a business unit table name,~dynamic variable from list B~,0),1).

    Clear as mud?

    I appreciate that sounds really confusing but i hope you get where im going with that.

    Like i said, the code works but ideally i would like to simplify that code and even more ideally, have that code more dynamic because as it stands, if i add another business unit table, all that code will have to be altered for every cell that code is situated in.

    EDIT: I've attached a cleansed version of the data and what I have. It works but i would like a more elegant way to get the data in column Q on the 'startrack' sheet.

    Thanks in advance.
    Attached Files Attached Files
    Last edited by hussco; 10-30-2017 at 05:01 AM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,228

    Re: Is there a way to simplify this?

    Attach a sample workbook (not image).

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate.

    Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: Is there a way to simplify this?

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    Re: How to use dynamic variables in an Index & Match function?

    Try

    Q6
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Copy down!
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to use dynamic variables in an Index & Match function?

    You might also use
    =IF(OR([@[Code: IT ONLY]]="",[@[Branch/
    Site Name:]]=""),"",IFERROR(INDEX(INDIRECT([@[Code: IT ONLY]]&"BU"),MATCH($P6,INDIRECT([@[Code: IT ONLY]]),0),1),""))

    I suspect that if you were to use one table rather than several on the Branch Sites sheet, you could make it much more efficient.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,228

    Re: How to use dynamic variables in an Index & Match function?

    Shukla's reply (#4) gives you the flexibility and removes the need to have named ranges.
    Last edited by JohnTopley; 10-30-2017 at 01:22 PM.

  7. #7
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: How to use dynamic variables in an Index & Match function?

    I added a helper column on the 'Startrack' worksheet (starting in cell U6) with the following formula (this was referred to as MainData[@Column1] in the updated formula in Q6 below). I couldn't enclose it in 'CODE tags as the formula itself includes the word code which messed up the formatting):

    =SUMPRODUCT(--(BusinessUnits
    Please Login or Register  to view this content.
    However, my suggestion is somewhat inflexible in that if additional BU's are added my formula would need to be updated. I'd agree with prior posts that a reworking to facilitate more flexible VLOOKUPS or INDEX / MATCH functions would be better again.
    Last edited by deadlyduck; 10-30-2017 at 07:28 AM.
    Excel 365 user. To unblock a downloaded macro-enabled workbook, go to your "Downloads" folder > right click on the workbook name > click 'Properties' > check the 'Unblock' checkbox. You can now open the workbook.

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,228

    Re: How to use dynamic variables in an Index & Match function?

    Removed by JT
    Last edited by JohnTopley; 10-30-2017 at 12:41 PM.

  9. #9
    Registered User
    Join Date
    10-27-2017
    Location
    Perth
    MS-Off Ver
    O365
    Posts
    2

    Re: How to use dynamic variables in an Index & Match function?

    You guys are great!

    Thanks for all your help.

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,228

    Re: How to use dynamic variables in an Index & Match function?

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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] Need to simplify this function - Thanks!
    By ffuller in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 11-18-2013, 04:37 PM
  2. Too Many If's - Help to simplify
    By batman1056 in forum Excel General
    Replies: 8
    Last Post: 12-07-2010, 12:19 PM
  3. Can simplify the given formula?
    By mingali in forum Excel General
    Replies: 14
    Last Post: 09-03-2009, 09:46 AM
  4. possible to simplify?
    By xLiquidFlames in forum Excel General
    Replies: 1
    Last Post: 02-23-2009, 03:29 AM
  5. Simplify formula
    By ShockG in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-01-2008, 09:21 AM
  6. Simplify and add to IF
    By Mark K in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-24-2006, 06:13 AM
  7. Simplify
    By ccl28 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2006, 05:50 AM
  8. [SOLVED] A way to simplify this please
    By Larry Empey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2006, 08:10 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