Using INDIRECT Function with Cell Reference

I want an INDEX, MATCH formula that uses INDIRECT to build the sheet reference (unless there is another choice). The INDEX, MATCH works fine if I "hard code" the sheet name. I cannot seem to get the syntax right to use INDIRECT. I have done this extensively in Excel and am trying to move exclusively to Numbers. This is a deal-breaker. Can anyone help? I have attached a screenshot with fake data and the text of the formula that works.




iMac 27″, macOS 10.15

Posted on May 6, 2021 5:02 PM

Reply
Question marked as Top-ranking reply

Posted on May 6, 2021 6:26 PM

It is just like Excel except for the difference in how they construct their references.


Unless I made a typo,

B2 =INDEX(INDIRECT(A2&"::Table 1::AC2:AC18"), MATCH(B$1,INDIRECT(A2&"::Table 1::AD2:AD18"),0))

10 replies

May 7, 2021 4:39 PM in response to Kokato

{=INDEX($D:$D,MATCH(TRUE,ISBLANK($A:$A),0))}

Assuming one header row and all cells above the "blank" one in column A have something in them,

=INDEX(D,COUNTA(A)+2)

The +2 = 1 for the header row + 1 row below the last entry (to the first blank).


{=INDEX('SheetName'!$C:$C,MATCH(1,(A97='SheetName'!$A:$A)*(B97='SheetName'!$B:$B)*($R$100='SheetName'!$J:$J),0))}

Given that column C is numbers and there should be only one match, SUMIFS can be used. If you for some reason made two or more payments on the same date; it will sum them up. INDEX(MATCH()) won't do that; this SUMIFS formula might be the better formula.

=SUMIFS($C, SheetName::$A,A97, SheetName::$B, B97, SheetName::$J, $R$100)


Summing across sheets

Bottom row is a footer row

Formula in B23 (the footer row) = SUM(B)

Fill right to complete the row

Formula in B2 =IFERROR(INDIRECT($A2&"::"&B$1),"")

Fill right and down to complete the table

I have a lot of sheets listed but only have Sheets 2-4 right now. As I add new sheets that match the sheet names in this list, their data will get included here automatically without me having to do anything. The IFERROR takes care of the missing sheets.


The first "date" in column A appears to be a number. That could be the cause of the error message from your SUMIFS formula.


It would be best if all the dates were formatted the same way. I cannot say why one column is "custom"; it looks just like the built-in format used in the other column. Select the column and reformat it with the built-in date format.






May 7, 2021 11:59 AM in response to Kokato

That does look like a lot to unravel. The slow calculations is making me think you have a large document with a lot of slow (for Numbers) calculations. That might be the true killer. How many sheets, how many tables per sheet, and how many columns and rows per table is it?


If you want to try tackling this, we can keep going at it until it either works or you are tired of it


It would also be desired to get away from INDIRECT as much as possible, if at all possible. I feel it is one of those "last resort" functions to be used when all else fails. It is fragile and can break if you make changes to your tables (like adding a new row or column that changes the references) or renaming a sheet or table. It will not adjust to any changes.


Some of your functions might be simple rewrites (or a rewrite plus a column of formulas to replicate the array formula) but I'm not sure what some of your array formulas are doing. In the past we have found that some array formulas did not need to be array formulas, they were legacy formulas that can be done better using newer functions, or were just a poor choice in the first place.


What does this formula do, for instance?

{=INDEX($D:$D,MATCH(TRUE,ISBLANK($A:$A),0))}


This next one might be handled with a new column to do the logic of =AND(A=A97,B=B97,J=$R$100). Again, I'm not 100% sure what it is doing.

{=INDEX('SheetName'!$C:$C,MATCH(1,(A97='SheetName'!$A:$A)*(B97='SheetName'!$B:$B)*($R$100='SheetName'!$J:$J),0))}


SUM of the same cell across a range of sheets/tables is not supported in Numbers. However, it can be replicated with a table that gathers all the cells to be summed. It is pretty simple to do with a column of sheet names and using INDIRECT (whether I like it or not) to put together the references, then a SUM to sum up the results. Or you can use actual cell references (not using INDIRECT).


I suppose the monolithic table of Excel can be an advantage at times. You will never have a reference error from referencing a cell that does not exist. You can have empty columns and rows in Numbers, too, if that makes things easier. I think what you ran into is Numbers does not import blank rows or columns unless it knows they are being used. That SUM formula couldn't be imported so I assume Numbers didn't know column AF was needed in all those tables.


The first SUMIFS formula will take the same kind of rewrite as what we did before. Numbers says it supports the * wildcard in this formula so I don't know what is going wrong there.


The SUMFS with the dates should have converted to =SUMIFS(I:I,A,">="&AA2,A,"<="&AB2)

Dates in Excel are stored as numbers. Most of the time they get converted to dates when imported, sometimes not. We'd have to see the formula and the data (column A and cells AA2 and AB2). My assumption is something stayed a number.


Charts with a lot of data points is another thing that slows down Numbers. You did not mention charts, I'm just throwing it out there as a possible cause of slowness.

May 7, 2021 8:48 AM in response to Kokato

Both Excel and Numbers can become sluggish when a lot of so-called "volatile" functions are used (functions that recalculate whenever a change is made to the document). INDIRECT happens to be one of those functions. I avoid INDIRECT if I can find another way to accomplish the same thing. Other volatile functions include RAND, RANDBETWEEN, TODAY, NOW, and OFFSET.


SG

May 7, 2021 10:48 AM in response to SGIII

I realize that Numbers (and the entire Apple environment) does not try to be like Excel and Windows. I embrace that (except when I don't). :-) I just don't want to be a pain with all of these questions. You did ask though...


=SUMIFS(INDIRECT("'"&$J2&"'!$C:$C"),INDIRECT("'"&$J2&"'!$B:$B"),"*"&$M$1&"*",INDIRECT("'"&$J2&"'!$K:$K"),"*"&$N$1&"*")

Using wildcards in a SUMIF or SUMIFS. I realize that I can use Badunit's formula as a template. I can't seem to get the wildcards to work.


=SUM(FirstSheet:LastSheet!AF3)

I realize that this does not work in Numbers. After I corrected the converted formula it is =SUM(UNION.RANGES(TRUE,CS 0082::Table 1::AF3,CS 6070::Table 1::AF3)). This is the shortened version because between FirstSheet and LastSheet are over 30 sheets. I believe this would be a complaint to Apple and not anything that can be solved with another formula, but before I fixed the converted formula, there were several #REF errors. Why? Because not all spreadsheets had a column AF. Once I added columns, I went back and pointed to the newly created columns in the existing sheets and the errors are gone. In the future, as I go beyond 2022, I will be required to add columns to every sheet again to make the formulas work. Crazy. Also, if I add another sheet, I need to go back and change all of my formulas to include the new sheet.


{=MATCH(TRUE,ISBLANK('SheetName'!$K:$K),0)}

I forgot about my array formulas.


{=INDEX($D:$D,MATCH(TRUE,ISBLANK($A:$A),0))}

Another array formula.


{=INDEX('SheetName'!$C:$C,MATCH(1,(A97='SheetName'!$A:$A)*(B97='SheetName'!$B:$B)*($R$100='SheetName'!$J:$J),0))}

Another array formula.


=SUMIFS(I:I,A:A,">="&AA2,A:A,"<="&AB2)

A:A, AA2 and AB2 all contain dates. Error generated in Numbers says "The formula compares a date to a number".


This is what I have found so far.



May 7, 2021 8:54 AM in response to SGIII

Thank you SGIII. This spreadsheet has not been sluggish at all in Excel and I believe it is sluggish in Numbers because of all of the unresolved conversions from Excel to Numbers. I should have realized that, but I am just reviewing all of the issues with the conversion. Badunit's formula worked once the spreadsheet finished calculating. I am now looking at all of the other formulas that don't and realizing this is a lost cause. I have lots of time on my hands, but not this much.


Thank you so much for your reply.

May 7, 2021 9:01 AM in response to Kokato

Kokato wrote:

I am now looking at all of the other formulas that don't and realizing this is a lost cause.


Maybe you are using "array formulas"? Or perhaps a note of date math? If you post examples of formulas that don't convert someone here can suggest ways to do the same thing in Numbers. As you've discovered, Numbers does not try be exactly like Excel. It has its own design philosophy. Many things are more easily done in Numbers. Others are better done in Excel.


SG



May 7, 2021 2:31 PM in response to Badunit

The slow thing seems to have resolved so I am taking that as a non-issue until proven otherwise.


This is my Quicken replacement since Quicken could not do what I wanted it to do.


The document is currently 48 sheets. All have columns A-AT (46 and will grow). Rows are from 70 to 17000 (only one is that long for a long-held since-cancelled credit card). There is only one Table per Sheet.


The sheets that do most of the calculations are the "accounts" sheets. There will be checking account, savings account, credit card, home loan, etc. Some of the headers are Date, Description, Transaction Total, Running Balance, etc. These do fairly simple calculations. Compute the Running Balance, compute sales tax based on a 4 column + 2 row HLOOKUP, add and subtract.


{=INDEX($D:$D,MATCH(TRUE,ISBLANK($A:$A),0))}

As part of each account sheet, I have a reconciliation area that looks just like an account statement. It begins with Previous (or Beginning) Balance, subtracts Payments & Credits, adds Purchases, calculates Ending/New Balance. The next line computes the total of the Purchases Not on Statement and adds, computes the total of Payments Not on Statement and subtracts to find Ending Balance. The array formula looks at column A (Transaction Date), finds the first Blank and returns the number in column D (Running Balance). If this number and the Ending Balance number are the same, you are Reconciled.


{=INDEX('SheetName'!$C:$C,MATCH(1,(A97='SheetName'!$A:$A)*(B97='SheetName'!$B:$B)*($R$100='SheetName'!$J:$J),0))}

This is used in a home loan sheet. In SheetName (the checking account that pays the mortgage), the loan payment is made in two rows: one is the Principal row and one is the Interest row. When I get the mortgage statement, I input the actual Principal and Interest numbers in the checking account. The array formula gets the amount from column C of the checking account. The matches are Date (A:A), Description (B:B) and the word Principal in the Memo column (J:J).


I don't understand the hesitancy to use INDIRECT (except as you explained it, of course). This is why I use it and I think you touched on it when you said you might use it. I have lots of accounts. If I add a new account, it is a pain to incorporate the account names/sheet names into the existing formulas. If I use INDIRECT, it is "automatic". I have a list of sheet names and can perform the same calculations on all of the sheets using INDIRECT. If I add a sheet, I add it at the bottom and sort (because inserting and deleting lines breaks all kinds of formulas). It is a beautiful thing!


The summing across a range of sheets may tip me over the edge. It creates too many problems with adding sheets and redoing formulas to accommodate those sheets. And, having to add rows and columns to every sheet (even those for sheets that may be closed accounts) is tedious and does not allow for easy growth.


I might have figured out the dates. As you said, in Excel the dates are stored as numbers. In my case, they are formatted as a date (m/d/yy). When I look in Numbers, The dates in AA and AB are formatted as Date & Time (with no Time). In A, the dates are formatted as Custom Format. There is a difference in the "Actual" also. See screenshots.



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using INDIRECT Function with Cell Reference

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.