0

I created an INDEX/MATCH function to retrieve data from a master Supply Risks worksheet in a master workbook (Supply Master Tracker) to populate into 20 columns into my tracking workbook (Personal Supply Tracker)

While my formula works, it does not seem to update when new rows and columns are added to the master workbook (which is a weekly occurrence), hence I have to update the formula to reflect the new column number.

This is quite tedious as I have to change the formula of 20 columns in many risks buy tracker workbook twice a week to match the new column numbers of the master worksheet. I was under the impression that Index Match functions allowed for new columns to be added.

Is there anything I can do to avoid having to alter the first range of my INDEX/MATCH function constantly? Maybe link it to the individual name of the column ie. (CE Comment) vs. (Column AK)?

Example: Personal Supply Tracker: Column N (Comments) cell N3 contained =IFERROR(INDEX('[Supply Master Tracker.xlsx]FY21 Supply Risks'!$AH$2:$AH$263,MATCH($A3,'[Supply Master Tracker.xlsx]FY21 Supply Risks'!$C$2:$C$263,FALSE))&"","")

However, the tracker updated so I had to change to: =IFERROR(INDEX('[Supply Master Tracker.xlsx]FY21 Supply Risks'!$AK$2:$AK$263,MATCH($A3,'[Supply Master Tracker.xlsx]FY21 Supply Risks'!$C$2:$C$263,FALSE))&"","")

Please advise of any suggestions.

EDIT: The data is tracking supply gaps by week, so each week three new columns are added

Three new columns are added to the master tracker worksheet on a weekly basis. They contain the tracking, supply, and revenue for the current week. The columns are then hidden as the quarter progresses, however, the weekly addition of these 3 columns subsequently alters all values that appear to the right of the added rows.

Table format – I’m not sure if the master sheet is in table format but I noticed there are numerical references the 300th row that list 1-18 for columns (C-Q) and then it stops right before the 3 weekly columns information is added.

3
  • Why do you need to use AK now instead of AH? By which logic do you, as a human, know that you need to shift the Index by two columns? If you can put that logic into words, it may be possible to translate it into a formula. Please post a simplified data sample of the first case and the second case. Does the data have headers? What is in the headers? Now, as a new user, read this carefully: EDIT your question to provide the additional detail, then post a comment to alert people following this question. Do not post clarification into comments.
    – teylyn
    Commented Oct 20, 2021 at 21:00
  • You need to change those absolute ranges in your formula. I think the best way to have the ranges "automatically" update is to use table references. This requires the master supply table to be in excel-table format, which I suspect you don't own that spreadsheet so can't update it to a table. I believe the workaround would be to "import" that master supply sheet into your own personal one, using table formatting on that import. Then reference your formulas to that table. After that, all you should need to do is update that "import".
    – gns100
    Commented Oct 21, 2021 at 17:51
  • @gns100 Importing the file will not solve the underlying issue. A data sample will show if lookups can be used to identify the column, and the solution will be very simple. Most important, however, is that Nina bothers to actually reply to the people who want to help.
    – teylyn
    Commented Oct 21, 2021 at 19:37

1 Answer 1

0

Your situation HAS to involve getting data in which the columns are shifted on you. Perhaps that is a data export from somewhere that has such changes and no way you can influence the creation or form of, or perhaps you are scraping a webpage. Or fifty other ways.

The reason I say this is that INDEX/MATCH (and the more recent XLOOKUP) DO in fact preserve you from this kind of problem vis-a-vis column insertions. Excel adjusts for such things, and does not fail. So the data must be coming in already placed so that it will be in a different column.

No problem, as it can be worked around. The easiest way is the one you ask about: search out the column based upon an unchanging column header. It WILL have to remain the same, of course, or you will need a further tweak or two for ease of use, depending upon the exact situation.

So then, how to do that? You will use match taking the known column header you are seeking and checking against a range that is the row of the headers, let's say row 1, and all the columns in not just the current data range, maybe that's as far over as column AZ at the moment, but farther right of that, let's say column BZ. So the range would be A1:BZ1. You start at column A so that your "MATCH number" (the column the header is in's column number) is easy to use. So if the data range is really C1:AZ263 (headers included), you don't have to get a MATCH number of, say, 1 for column C which is column 1 in the range, then add 2 to get the column 3 that it is in the larger world. Simpler to not have to adjust. So long as your unique column header is not in extra places in row 1, that's the easy way.

If you have the column from MATCH-ing on the column header, then the ADDRESS function will take that and a row number and give you their Excel address. You want to start looking for your lookup value in row 2, so you know it to start and are learning what column to make an address for. Today it turns out to be column AK, so column 37. ADDRESS then takes row 2 and column 37 and spits out the address $AK$2.

You can do that twice, once giving it row 2 and once giving it row 263 to get $AK$2 and $AK$263. If you make those into a string and slip in &":"& between them, you have: $AK$2:$AK$263 . Not a "real boy" just yet, but the INDIRECT function will take a string like that and make it into a real address: INDIRECT($AK$2:$AK$263) is a real address to Excel and returns the column of data into the formula.

The INDEX/MATCH formula you are using is basically two parts. The inner part is the MATCH function which returns the row you need and the INDEX part, the outer part, takes it and finds that row in the column of data it is indexing. In the following formula, the lookup value typed by someone is in cell N3, it is used to look in column AK which is labelled CE Comment to find the index (row, basically) of the lookup value in N3. That index is passed on to the INDEX function at the start of the formula as the desired row to return. The range INDEX is indexing is column C which I've given the label pig since you did not give its name.

So, the logic is:

  1. Enter a lookup value in N3.

  2. Use MATCH (twice) on the pig headered column to find its column number.

  3. Pass that and the starting row number to ADDRESS to get a proper address for the beginning of the lookup value search range.

  4. Pass that and the ending row number to ADDRESS to get a proper address for the end of the lookup value search range.

  5. Slip the colon in between 3 and 4, above.

  6. Wrap all that in INDIRECT to make it a real range to Excel.

  7. Use MATCH and the lookup value on that range to get the index of the matching value.

  8. If happy that column will never need this kind of looking up, then just use its $C$2:$C$263 address directly and skip the above.

  9. That half of an INDEX/MATCH finished, build the range you tell INDEX to find the answer in in exactly the same way, just using the CE Comment column header.

  10. So now, when the column order is shifted on you, you still locate the CE Comment column automatically and always have the right answer.

Formula:

=INDEX(INDIRECT(ADDRESS(2,MATCH("CE Comment",A1:BZ1,0))&":"&ADDRESS(263,MATCH("CE Comment",A1:BZ1,0))),MATCH(N3,INDIRECT(ADDRESS(2,MATCH("pig",A1:BZ1,0))&":"&ADDRESS(263,MATCH("pig",A1:BZ1,0)))))

You need to change the column headers to match your real ones. The 2's in it look like they should remain the same. The 263's can be changed if the table grows downward. Of course, you'd add to the addressing strings to put in the references like '[Supply Master Tracker.xlsx]FY21 Supply Risks'! to properly complete the bare address ADDRESS generates. Like so:

INDIRECT("'[Supply Master Tracker.xlsx]FY21 Supply Risks'!" & ADDRESS(2,MATCH("pig",A1:BZ1,0)) & ":" &...etc.

All just part of building the strings needed.

After you get things going, there are all kinds of ways you can "automate" every last bit of it. Starting and ending rows can be calculated and/or located, and so on. But this will get you on your way.

There are other ways to get the addresses too, and if you find one you prefer, you can just convert to that.

If you have XLOOKUP it becomes easier yet, lots in this case. If you have LET, you can make it all look vastly clearer to anyone looking at the formula.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .