Get cell range through getting cell addresses with formulas - excel

I'm trying to write a formula that will allow me to count a number of lines used between a cell range. I created a test formula to see if my thought process was straight. For my test I put a header called "NUM" (A1) and then on the same column a bunch of rows of "1"'s then another header beneath the first array called "NUM2" (column A but could be anywhere) with more "1"'s under that as well. I'm using a formula to find the cell address to find the first header which is
=CELL("address",INDEX(A:A,MATCH("NUM",A:A,0),1))
which printed ($A$1) and then combining it with
=CELL("address",INDEX(A:A,MATCH("NUM2",A:A,0),1))
which printed ($A$14) to get the second header name, after that I'm using a COUNTIF function to count the ones like so:
=COUNTIF((CELL("address",INDEX(A:A,MATCH("NUM",A:A,0),1)))&":"& CELL("address",INDEX(A:A,MATCH("NUM2",A:A,0),1))),"1"))
and I thought that if I didn't use the formulas inside the formulas it would look like:
=COUNTIF($A$1:$A$14,"1")
which prints my desired number of 12. My question is can I not put the combination of the two formulas inside of the bigger COUNTIF statement?

You are just missing an INDIRECT which will turn your string into a cell reference.
=COUNTIF(INDIRECT(CELL("address",INDEX(A:A,MATCH("NUM",A:A,0),1)) & ":" & CELL("address",INDEX(A:A,MATCH("NUM2",A:A,0),1))),1)
A simpler version (assuming column A) would be
=COUNTIF(INDIRECT("A"&MATCH("NUM",A:A,0)&":A"&MATCH("NUM2",A:A,0)),1)
You could also use OFFSET.

Related

How to Lookup First column that is not empty and Return Corresponding Column Header In an Excel block of cells

I am trying to Lookup First column that is not empty and Return Corresponding Column Header In an Excel block of cells (I think called Array?)
For example:
In this picture, I want to look at all of the entries in B4:G9, and have my formula tell me the first column not to be empty is the column labeled as 1.
I have the following formula so far that seems to work, where I search each row, have each row return the column header that the first non-zero number shows up in, and then search the minimum of the returned column headers. However my actual data has more than 100 columns and 100 lines, so I am looking for something cleaner.
=MIN(
INDEX($B$3:$G$3,MATCH(TRUE,INDEX((B9:G9<>0),0),0)),
INDEX($B$3:$G$3,MATCH(TRUE,INDEX((B8:G8<>0),0),0)),
INDEX($B$3:$G$3,MATCH(TRUE,INDEX((B7:G7<>0),0),0)),
INDEX($B$3:$G$3,MATCH(TRUE,INDEX((B6:G6<>0),0),0)),
INDEX($B$3:$G$3,MATCH(TRUE,INDEX((B5:G5<>0),0),0)),
INDEX($B$3:$G$3,MATCH(TRUE,INDEX((B4:G4<>0),0),0)))
This formula should work for you, adjust the $B$4:$G$9 to match your actual dataset:
=INDEX($3:$3,1,MIN(IF($B$4:$G$9<>0,COLUMN($B$4:$G$9),COLUMNS($3:$3))))
Note: Depending on your version of Excel, you may have to confirm the formula with CtrlShiftEnter instead of just Enter. That will force the formula to be calculated as an array. You'll know you've done it correctly when the formula is surrounded by curly braces {formula} (the braces aren't put in manually, they're put in automatically upon successful array entry via CtrlShiftEnter)

Find the value located in the bottom row in excel

Let's say I've got a table like this
What I want to do is get a formula that always gets the last value in column B and put it on cell D1, so in this case I want to get the value "21" but then if I keep adding values to this list I want to always get the value placed in the last row on that list. is there a way to do this?
Found a way to do this.
=LOOKUP(2,1/(B:B<>""),B:B)
Sure. Use COUNTA(B:B) to count all the non-empty cells in column B, use ADDRESS() to build the address of the last cell and use INDIRECT() to pull the value of the said address.
or you can use INDEX() to combine indirect and address

Using CELL with ROW, INDEX, and MATCH Functions

I'm working on trying to display the contents of a cell if data in the same row meets a certain criteria. In the case I am currently working on, if a value in a column is a maximum value I want to display the contents of that cell that is in the same row but different column.
My existing code is shown below:
=CELL("contents","B" & ROW(INDEX(E3:E75,MATCH(MAX(E3:E75),E3:E75,0)))
I know the "B" & ROW(INDEX(E3:E75,MATCH(MAX(E3:E75),E3:E75,0))) works as I have tried it in a different cell and it gives me the output I expected which was a string "B#". My issue is I can't seem to do anything useful with it, as its not acting as a cell input in formulas. I'm not quite sure what my issue is, but I would assume it has to do with syntax of how I'm inputting the data into the formula.
Just use the correct range in the INDEX and skip all the other work:
=INDEX(B3:B75,MATCH(MAX(E3:E75),E3:E75,0))

Excel Performance - INDEX-MATCH combination

I am using excel to create data sets that are used in a vba application later. I am using this formula:
=INDEX(BaseData!$L$2:$L$10000;MATCH(DataSet!D5&DataSet!E5&DataSet!K5;INDEX(B‌​aseData!$B$2:$B$10000&BaseData!$C$2:$C$10000&BaseData!$D$2:$D$10000;0);0))
usually with a range from f.ex.: A2 - A10000, because my data can be differently long and often vary in data selection.
However, this slows my excel extremely down. I switched to manual calculations, but then, when activating automatic again, my excel instance takes extremely long and often crashes.
I also tried to past some data, but when creating a new dataset, I have to pull the formula down again and sometimes through this errors occur in my data set.
Any suggestions what I can do to make the INDEX-MATCH formulas more performant?
I appreciate your replies!
UPDATE
I guess a lot of performance goes away because index-match does not select the exact range, but also counts in blank rows. How to get the exactl range with index match automatically?
As I mention in my comment above, as long as this is a 'regular' formula and not an Array Formula, you may find success simply replacing "A1:A10000" with "A:A". However barring that, you can create a cell which will calculate reference the number of rows of data which you have, and then use that cell to indirectly reference the complete column with data in it.
CALCULATING YOUR DESIRED RANGE
For the following example to work, I assume that: Column A includes an index key in the form of numbers only; Column A includes no numbers in the header and above; and that the index rows are continuous, with no breaks. Start with the following formula:
=COUNT(A:A)
If my assumptions above hold, then this will return the number of data elements in your table. Once we know where this data starts, we can use this COUNT to determine where it ends. Assume your header is in row 2. (I like to include the header so that if you insert a row beneath the header, Excel picks up that you want to include the new row in your formulas).With that in mind, this formula will create the Excel-style reference which finds the last cell in column A which has data in it:
=ADDRESS(ROW(A2)+1+COUNT(A:A),COLUMN(A2),1,1)
Assuming 50 rows of data [which start at row 3, below the header], and all other assumptions above, this formula will return the text result "$A$53".
If you wanted to do the same thing, but instead return the full range in Column A where data exists (from the header to row 53), you could do as follows:
=ADDRESS(ROW(A2),COLUMN(A2),1,1)&":"&ADDRESS(ROW(A2)+1+COUNT(A:A),COLUMN(A2),1,1)
This returns the text string result "$A$2:$A$53", which is a reference to the full index of unique ID values. It will automatically move around as you would generally expect if you insert any rows or columns. Now assume for your INDEX that you want to pull the same data, but for column B, instead. The formula will be exactly the same, except that where I have "COLUMN(A2)" above, replace with "COLUMN(B2)".
REFERENCING YOUR CALCULATED RANGE
So now you have the address of your proper, limited columns - but how do you actually reference those areas in a formula? By using the INDIRECT function. INDIRECT says "Evaluate some specific criteria. It will create a cell reference. Now look at that cell reference." In its simplest form, this could look like this:
=INDIRECT(A1)
Assume that A1 holds the value "B5". Indirect will pick up the value "B5", and instead of displaying "B5", it will go to B5, and pick up the value there. So to use this with the above, wrap the whole thing in the INDIRECT function. Instead of picking up the text string "$A$1:$A$53", it will actually now reference that range properly. Like so:
=INDIRECT(ADDRESS(ROW(A2),COLUMN(A2),1,1)&":"&ADDRESS(ROW(A2)+1+COUNT(A:A),COLUMN(A2),1,1))
USING A NAMED RANGE
But that is a very long formula to have, and you won't want to use it within a specific cell for a simple INDEX/MATCH. Instead of entering these formulas in cells (although you could), I recommend you go to the Formula Ribbon -> Name Manager -> New Name. Call the name for the index of A "ID_COLUMN". Call the name for the index of "B_COLUMN" (or something more specific).
FINAL FORMULA
Now, if you wanted to make an INDEX/MATCH of your table, which automatically grows/shrinks as you change the data, your formula would look like this [this would, for example, pick the row from column B where column A has the number 100]:
=INDEX(ID_COLUMN,MATCH(100, B_COLUMN, 0))

Excel: VLOOKUP from a different Sheet

I know there's several posts about this, here and other places, but I seem to get errors no matter which method I try.
I'm trying to fill an adjacent cell with a value based on the corresponding value from a list of values. For example, there's a list of Test -> Action pairs, defined in two columns. In another cell, I want to type in a value which exists in column B, and then fill the adjacent cell with the corresponding value in column A.
Here's my Sheet.
The columns "Actions" and "Tests (test groups)" define the corresponding values.
I'm using VLOOKUP in the "Test (test grop)" column (below the first two columns, from row 10 and down), to fill the cells when I'm entering a value in the "Action" value. Simple enough.
However, now I need this exact functionality in another sheet. I need to move the "Action" and "Test (test group)" columns - row 10 and down - to another sheet, and still reference the values in this sheet (row 2 - 6).
I've tried INDIRECT and a couple of other alternatives, and all give me either "#REF" or "#VALUE" in the cell where I use VLOOKUP.
Anyone able to explain how to do this, related to this example?
You need to add the worksheet name to your formula. Use single quotes if you have spaces or special characters in the name. Like this:
=VLOOKUP(A1,'sheet-name-with-dash'!$A$1:$B$9,2,FALSE)
may seem out of place, but whenever I see this kind of problems (in defining and using ranges) I think of the Excel option to define those ranges (like in Ctrl+F3, Name Manager).Showcase:
select your area: in your case A2:B6,
hit: Ctrl+F3,
name the range: i.e. LookupRange
use that range in Vlookup formula like: Vlookup($A12,LookupRange,2,0)
I do not use this on regular basis,but might get handy in a workbook with many sheets, ranges, formulas. Try this for fun at least.
Hope it helps.

Resources