Excel: How to add an index that ignores empty cells - excel

I am given an excel table. I want to include an additional column which simply contains an index. The column to the right of this index will have some text in it, or be empty. I want to have an index whenever the cell to its right is NOT empty.
Example:
1 Some Text
2 Some Text
3 Some Text
4 Some Text
I was hoping to achieve this by applying the following formula:
=IF(B7="";"";MAX(A4:A6)+1)
The cells given in the MAX() function are all the cells that come before the current cell. This formula works fine, but unfortunately only whenever there are not more than 3 empty cells in between.
Can I make this formula work for an arbitrary amount of empty cells in between?

with data Like:
In A1 enter:
=IF(B1="";"";1)
In A2 enter:
=IF(B2="";"";1+MAX($A$1:A1))
and copy downwards:

The formula in A1 I've used is:
`=IF(AND(B1<>"";ROW()<>1);MAX(INDIRECT("A1:A" & (ROW(A1)-1)))+1;IF(AND(B1<>"";ROW()=1);1;""))`
And I guet this dragging it down:
How it works?
The trick here is MAX(INDIRECT("A1:A" & (ROW(A1)-1)))+1. With INDIRECT you can reference a specific range. The index are always in column A and starts in row 1, that's why I typed "A1:A". But you want to get max value from A1 to Activecell-1, that's why I added (ROW(A1)-1). This will get the row number of active selection minus 1.
IF(AND(B1<>"";ROW()<>1) This is just to check if adjacent cell is not empty, and row number is different than 1. If true, then do the previous step. If false, then do step 3.
If the first IF returns False, could be because adyacent cell is empty, or because row number is 1. So we need to check that with IF(AND(B1<>"";ROW()=1). If true, means B1 is not empty and row number is 1, so index must be forced to be 1. You cannot calculate the max value of a range previous to A1 or it will raise an error. IF this second IF returns False, means adyacent cell is empty, so we do nothing.

Related

Count non blank cells above a cell until first blank

how do I count how many non blank cells until the first blank above a cell.
For example, it is 6 non blank cells from C15 to C6 until there is a blank cell C9. The array formula I know =Match(1,--(C5:C16=""),0)-1, always start counting from C5. Is there way to start backwards, like start counting from C16?
enter image description here
Instead of MATCH use MAX: `=MAX((C$5:C16="")*(ROW(C$5:C16))'.
Note, I used the Range you used in your example and locked the row at C$5 by using $-sign. That way it will not change if you drag down the formula.
This formula will return the ROW # of the condition met. If used in combination with INDEX I recommend referencing the whole column, like so:
`=INDEX(C:C,MAX((C$5:C16="")*(ROW(C$5:C16)))'
I noticed you substracted 1 of the row. You can do the same after this formula.

Using nested IF function in excel: is there a way to check next row for same IF function?

Let's say I have a simplified table of only 2 columns. Column one is Group number, with groups of different sizes. Column 2 is also numbered but has a lot of blanks.
I basically want to fill these blanks with the next NOT blank, if it is still in the same first-column-group.
I don't know if it works to show a table here, but this is what it is now and what I want to achieve with a simplified dataset:
What I tried is to use an If function. First, it checks if B1 is blank. If it is blank, I want it to check if A1 is the same "group" value as A2. If that is also true, then I want the formula to return me the value of B2. However, if B2 is also blank I want it to loop: Check if A1/A2 are the same as A3, and then give the value of B3. And continue. Plus! If B1 is not blank to begin with it just needs to return the value B1. And if B1 is blank but A1 is not the same group as A2, I want it to remain blank (or 0 is also fine).
The only way I did this was making an extremely nested if function that kept repeating for the [if true] part, which looks like this:
=IF(B2="";(IF(A2=A3;
(IF(B3="";(IF(A3=A4;
(IF(B4="";(IF(A4=A5;
(IF(B5="";(IF(A5=A6;
(IF(B6="";(IF(A6=A7;
(IF(B7="";(IF(A7=A8;
(IF(B8="";(IF(A8=A9;"xx";""))
;B8));""));B7));""));B6));""));B5));""));B4));""));B3));""));B2)
However, sometimes there are 100+ blanks within one group, and I'm trying to avoid looping 100+ repetitions of that formula.Right now, when there are not enough loops for within a group, it shows the xx. Is there no way to just replace the B1 by a continuous string of cells of column B? I looked at the Row function but it only works when you pull it down if I understand it correctly.
Would really appreciate the help!
If you did want to try a formula, something like this will work:
=IF(B2<>"",B2,IFERROR(INDEX(B2:B$19,MATCH(A2,IF(B2:B$19<>"",A2:A$19),0)),""))
entered as an array formula using CtrlShiftEnter in my version of Excel (2019).
The inner IF statement produces an array where only the rows that have a number in column B will have a value equal to the group value in column A, otherwise it will default to FALSE, so you get
False
False
1
False
1
False
False
2
False
...
then you do a Match on the value of A which is in the current row in the array to find the next row where there is a non-blank value in column B (3 in the first case). Then Index produces the corresponding value from column B in the row found by the Match (1 in the first case).
If the match fails because there are no further entries in the current group (like in rows 15 and 16 of the screenshot) then it will call in the "" from the IFERROR statement, so you get a blank in that row.
You could change the IFERROR to zero if you preferred to have zeroes in those cells rather than blanks:
=IF(B2<>"",B2,IFERROR(INDEX(B2:B$19,MATCH(A2,IF(B2:B$19<>"",A2:A$19),0)),0))

Check if text exist in rest of Column, and if so, use info from that row it is in

I'm after a way to a cell to check another cell that I'm inputting text into, and for it to see if that text value is the same anywhere else in the column, and if so, it grabs the number value which is in the same column as itself but in the row of the text that checked for.
So if you use picture, you can see I've currently got E7 selected. I'm wanting it to check the "GOLF COURSE" column for any other row that contains the same text it has in it's own row. For this it's "Course1". I'd like it to check through the rest of column B if there are any matches for "Course1" which there is in B3. If it matches I'm wanting it to then use the value that's in same column as it (E) but the same row as the matched text in column B. In this case I would want it to copy the value that is in E3.
If there wasn't a match (as it's a new course lets say) then I need to be able to just click on the cell and input the numbers needed, which I would be able to do anyway but just throwing it in for sake of info.
I've tried all sorts of googling and thinking how I could possibly do it but it's too difficult for my amateur knowledge of Excel.
I believe you are looking for INDEX/MATCH:
=IF(COUNTIF($B:$B,$B7)>1,INDEX(E:E,MATCH($B7,$B:$B,0)),"New")
I added a COUNTIF check to ensure that the same course exists more than once in column B, without it, you would be getting a circular reference formula (which would also happen with the above formula if the same course appears more than once, but you use this formula on the first occurrence of that course, so make sure do not use it the first time you fill out the PAR scores for a particular course).
Merged Cells Messing With INDEX/MATCH
The Formula
Copy the following formula into cell E7:
=IF(AND($B7<>"",$D7="Par"),IF(ISERROR(MATCH($B7,$B$3:$B5,0)),"Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))),IF(AND($B6<>"",$D7="Strokes"),IF(ISERROR(MATCH($B6,$B$3:$B4,0)),"Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1)),""))
Image
How
We are creating the formula in cell E7.
MATCH
Syntax: MATCH(lookup_value,lookup_array,match_type)
We will use MATCH to find the position of COURSE1 in the above
cells of column B.
The 1st argument is lookup_value which will be the cell in the same
row of our row (7) in column B: B7 where we will lock only the
column (we will not be searching in other columns): $B7.
The 2nd argument lookup_array will be a range. The first cell will be
cell B3 whose row and column we'll lock, because we will always
start the search from this cell in every other cell to the left or
below: $B$3. The last cell will be B5 where we will lock only the
column: $B5.
And finally we will use 0 as the parameter of the 3rd argument
match_type to find an exact match.
Now were ready to write our MATCH formula:
=MATCH($B7,$B$3:$B5,0)
Which will return 1 i.e. an exact (0) match of B7 was found
in the 1st cell of range B3:B5.
We don't want 1 (E3), but the value in the cell (5).
INDEX
The INDEX function has 2 syntaxes where we will use the 2nd:
Syntax 2: INDEX(reference,row_num,column_num,area_num)
Since were using a one-column range we can safely omit the arguments row_num and column_num, which leaves us with:
Modified Syntax: INDEX(reference,area_num)
The INDEX function used this way will return the area_num-th value
of reference i.e. in our case if area_num is 1 it will return the
1st value in our column range, if it is 2, then the 2nd, etc.
The 1st argument reference will be the same sized range of our
MATCH range in column E: $E$3:$E5 where we will remove the
column locks because we also want to return results for other
columns: E$3:E5.
The 2nd argument area_num will be our MATCH formula.
Our current formula looks like this:
=INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))
which will return the value of cell E3: 5.
Final Adjustments: IF, AND and ISERROR
That would have been almost (Error Checking) all if the cells in column B weren't merged. Therefore we have to use IF to determine if the row in which we're writing the formula contains either Par or Strokes and adjust our so far created formula for both conditions:
=IF($D7="Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))
=IF($D7="Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1)
=IF($D7="Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0)),$D7="Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1))
and (3rd condition) check in column B if there is a value in the row where we're creating the formula for a row containing Par, or the row above for a row containing Strokes, using AND:
=IF(AND($B7<>"",$D7="Par"),INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0)),IF(AND($B6<>"",$D7="Strokes"),INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1),""))
Finally we have to add some error checking, because if the match was not found the formula will produce and #N/A error:
=IF(AND($B7<>"",$D7="Par"),IF(ISERROR(MATCH($B7,$B$3:$B5,0)),"Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))),IF(AND($B6<>"",$D7="Strokes"),IF(ISERROR(MATCH($B6,$B$3:$B4,0)),"Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1)),""))
Now we are ready to copy the formula to the right and below as far as we need.

Excel: Search A Cell To See If A Cell From An Entire Column Is Present

Having trouble with a formula to solve this problem. I can do it when comparing one cell but can't figure out how to do it to check the entire column.
What I have two columns. Column A is a list of keywords. Column B is a list of Cities.
I want to compare all of Column B to see if any of those cities are contained on a cell by cell basis in column a
If I just use =ISNUMBER(SEARCH($B$2,A2)) it will compare all the cells in column A to B2 and the formula works. But I have a few hundred cells in Column B that I want to compare A2 too. I want to know if any of the words in Column B show up in the cell A2
Instead of just $B$1 I'd like to compare the entire B column (Like B:B but that doesn't work) and see if any of the words in Column B are in Cell A2.
Hope that makes sense.
Using the whole column B:B is not possible because of performance issues. But you could using a part of the column $B$2:$B$100 within an array formula.
Example:
Formula in English notation:
{=SUM(--ISNUMBER(SEARCH($B$2:$B$67,A2)))}
This is an array formula. Input it into the cell without the curly brackets and then press Ctrl+Shift+Enter to confirm. The curly brackets will then appear automatically.
How it works:
In array context ISNUMBER(SEARCH($B$2:$B$67,A2)) takes all values of $B$2:$B$67 into the formula and results in an array of {TRUE, FALSE, FALSE, TRUE, ...} dependent of whether the value is found in A2 or not. The -- gets the boolean values as numeric 0 or 1. The SUM then sums the array. So it counts how often 1 will be present.
Edit:
This needs the $B$2:$B$67 filled with values because otherwise the "" from empty cells will always be found. So to be more flexible we should check whether cells in $B$2:$B$1000 are empty and excluding those then.
{=SUM(($B$2:$B$1000<>"")*ISNUMBER(SEARCH($B$2:$B$1000,A2)))}

Find the first empty cell in the same column/row

I am trying to work out a formula that will give me the row number of the first empty cell in a column. Currently I am using:
=MATCH(TRUE, INDEX(ISBLANK(A:A), 0, 0), 0)
This works fine, unless the formula is put in the same column as the column I am searching in, in which case it does some sort of circular reference or something. Is there a formula I can use instead which will work when placed in the same column as it searches in?
Another way to do it
=MIN(IF(A2:A6="",ROW(A2:A6)))
you have to press CTRL+SHIFT+ENTER
The difference is that this will give you the Row number of the first empty cell
The previous answer will give the position (how many rows from the starting row) of the first empty cell... Both ways are valid depending on your needs
All you have to do is count the non blank cells in a column : COUNTA
e.g.
=COUNTA(E:E)
If you want to find the first blank cell from further down the column, then set the column range e.g. E23:E100 and add the cell number -1 to it.
=COUNTA(e23:E1000)+23-1
=MATCH(TRUE,INDEX(ISBLANK(INDIRECT("R[1]C:R1048576C",0)),0,0),0)+ROW()
This formula above returns the row number of the first blank cell in the current column and below the current row, but it does not need to be entered in row 1 of the worksheet.It replaces the A:A target range with a range that starts in the next row and continues to the end of the sheet and then adds the current row number to the result to add the skipped rows back in. This avoids the circular reference since it starts on the next row.
Using the INDIRECT(ref_text, [a1]) function with the second argument set to FALSE or 0 allows you to pass ref_text in R1C1 notation (eg. B5 as R5C2).
The R1C1 notation also has a lesser known syntax for describing a location as an offset from the current position. If the number following the R or C is enclosed in square braces then it is treated as a +/- offset from the current cell or zero offset if omitted (eg. "R[-1]C[-1]" in cell B5 returns A4 and "RC" in B5 returns itself B5).
The R1C1 location of R[1]C:R1048576C from the formula defines a range starting at the current cell with a RC offset of 1,0 and ending at fixed row 1048576 with a 0 column offset from the current cell. When placed in cell C3 it will be equivalent to C4:C1048576 and in A1 is equivalent to A2:A1048576. If you needed to dynamically set the max row number, you use INDIRECT("R[1]C:R"&ROWS(A:Z)&"C",0) but since current version Excel has a row limit of 1,048,576 it makes sense to just set it.

Resources