Get the count of not null values before the cell - excel

As shown in the image in Col2 I need to get the count of not null values in the Col1 before the cell.
For cell B2 there is only one value A hence 1.
For cell B4 it should be 2 as there are 2 values A & C.
Same way for B5, 3 (A,C,D)
Data:
A B
1 Col1 Col2
2 A 1
3
4 C 2
5 D 3
6
7 F 4
I have tried:
B1 Cell = COUNTA(A2:A2)
B2 Cell = COUNTA(A2:A3)
B3 Cell = COUNTA(A2:A4)
However I cannot drag this formula as it will change the cell reference.
Can anyone suggest any way to get this done in a single formula which can be applied to all the cells through out the column.

Try this:
=IF(A2<>"",COUNTA($A$2:A2),"")

Related

Excel: search value in array and fetch row and column name

I have a spreadsheet of available samples across 45 boxes, arranged stacked with column headers from 1 to 10 and row headers from A to J. I'm looking for a way to fetch the box, row and cell number if I lookup an ID (prefixed with B).
Sheet 1 is a list of animal IDs that I want to know if a sample is available for
Sheet 2:
Box 1
1 2 3 4 5 ... 10
A B43 B12 B3 B6 B103
B B13 B14 B78 B51 B63
C B78 B33 B99 B43 B92
...
J
Box 2
1 2 3 4 5 ... 10
A B2 B6
I have tried doing nested if functions by columns:
if(match(A2, Sheet2!$B$2:$B$521,0),"1",if(match(A2,Sheet2!$C$2:$C$521,0),"2","")
...but I've been getting #N/A if A2 is in column C.
I've resorted to re-labelling the left-most column to Box 1 A, Box 1 B, Box 1 C... so on, and doing:
=index(Sheet2!$A$2:$A$521,match(A2,Sheet2!$B$2:$B$521,0),0)
...and duplicating the function for **Columns 1 to 10*.
Sheet 1:
Animal ID Col1 Col2 Col3 Col4 ...
B12 . Box 1 A . .
B43 . . . Box 1 C
...
Is there an easier way to fetch the location of a sample from an array?
If your Sheet2 looks like this.
and you want the data like this in Sheet1.
Then enter this formula in Cell B2 of Sheet1 and drag it down and across.
=IFERROR(CONCATENATE(INDEX(Sheet2!$A:$A,(MATCH($A2,Sheet2!B:B,0))-MOD(MATCH($A2,Sheet2!B:B,0)-1,12),)," - ",INDEX(Sheet2!$A:$A,MATCH($A2,Sheet2!B:B,0))),".")

Fill blank cell in Excel with value with same ID

I'm not so advanced in excel I need help if is it possible to do.
I have an excel with this column:
ID - Value1 - Value2
I need to update the value1 (or value2):
- only if are blank AND only if the row has the same ID
I make an example, I have this table:
ID Value1 Value2
A1 1 100
A2 2
A3 3
A4 1 200
A5 2 250
Iwould like to fill all the empty cell in this way
ID Value1 Value2
A1 1 100 200
A2 2 250
A3 3
A4 1 100 200
A5 2 250
Thank you for any help.
Ok, so your data is a mixture of numbers and texts. You can generate two new columns with the desired values using formulas. Choose two new, adjacent columns, say D and E, and enter this CSE formula in row say in cell D2:
D2:
=IFERROR(IF(ISBLANK(B2),INDEX(B$2:B$99,
MATCH(1,($A$2:$A$99=$A2)*(1-ISBLANK(B$2:B$99)),0)),B2), "")
CtrlShiftEnter
Enter the formula in D2 with CtrlShiftEnter and then copy/paste in the cells of columns D and E (or as I said any two adjacent columns).

How to match columns and adding blank rows in excel

I have an excel file with 5 rows in column A and B, and 3 in column C and D (in reality though, I have a couple of hundreds of rows). Column B consists of text belonging to A, and D of text belonging to C. Column C has some of the values found in column A.
It looks like this:
A B C D
1 1 stringA1 1 stringC1
2 2 stringA2 2 stringC2
3 3 stringA3 4 stringC3
4 4 stringA4
5 5 stringA5
Now, I would like to match the numbers in column C with those in A, so that matches are put in the same row. For those rows in A for which there is no match in C, I want to have blank cells after column B.
It would look like this in this case:
A B C D
1 1 stringA1 1 stringC1
2 2 stringA2 2 stringC2
3 3 stringA3
4 4 stringA4 4 stringC3
5 5 stringA5
I have some idea that I should use VLOOKUP and maybe Conditional Formatting, but unfortunately I am not very experienced in excel. Could someone please suggest a way to do this?
Enter the following formula in Cell E1:
=IF(IFERROR(MATCH(A1,$C$1:$C$5,),"")<>"",INDEX($C$1:$D$5,IFERROR(MATCH(A1,$C$1:$C$5,),""),1),"")
and this one in Cell F1:
=IF(IFERROR(MATCH(A1,$C$1:$C$5,),"")<>"",INDEX($C$1:$D$5,IFERROR(MATCH(A1,$C$1:$C$5,),""),2),"")
Using Helper Column:
You can also do this using a helper column.
In Cell E1 write:
=IFERROR(MATCH(A1,$C$1:$C$5,),"")
Then in Cell F1 write:
=IF(E1<>"",INDEX($C$1:$D$5,E1,1),"")
And finally in Cell G1 write:
=IF(F1<>"",INDEX($C$1:$D$5,E1,2),"")
This was answered by #user3514930 to a question here.
You can directly use this formula in D2 and copy downwards:
=IF(A2 = C2, A2, "")
Now if you have formulas in A2, C2, type in those formulas in place of A2, C2 in the above.

Excel: Given a cell in column B as input, how could I find out the lowest cell of A which B > A?

I have an excel sheet, which value of column A >= B in the same row.
I would like to know given a cell in column B, how could I find out the lowest cell of A which B > A? (It should return a cell address but not the value)
For example, the following shows cells from A1 to B7 in a sheet:
A B
------
1 | 1 1
2 | 3 2
3 | 5 3
4 | 7 4
5 | 9 5
6 | 10 6
7 | 15 10
Now I would like to input B6, then it should return A3 (since 6 > 5)
Another example, if I input B7, then it should return A5 (since 10 > 9)
Is there any approach (or similar approach) by using excel formula? Or should I use other methods?
If your input value is in cell E1, and your return value is in cell E2 (as shown in below image), then you can use this formula in cell E2:
=IF(E1="","",INDEX(A1:A7,MAX(1,MATCH(TRUE,INDEX(A1:A7>=E1,),0)-1)))
Input Cell E1 (enter the address from column B here)
F1: =ADDRESS(LOOKUP(2,1/(INDIRECT(E1)>ColA),ROW(ColA)),1,4)
Given your data, if you enter B6 in E1, A3 will show in F1

extract data from column based on subset of data from other other column

This is how my data looks like:
C1 C2 C3
1 1 a
2 2 a
3 3 a
4 4 a
7 5 a
8 6 a
9 7 a
10 8 a
9 a
10 b
You see that C1 is a subset of column C2. I want now to extract only the data from C2 - together with the corresponding value from C3 - that matches C1. The extracted data just needs to be copied to another column
Could someone give me a hand?
Assuming your data in C1 starts from A2, do the following:
Type in cell D2 (column C4): =IFERROR(VLOOKUP($A2,$B:$C,1,0),"")
Type in cell E2 (column C5): =IFERROR(VLOOKUP($A2,$B:$C,2,0),"")
Autofill both formulas.
This will give you what you want, missing values will be shown as blanks. If you want concatenate both parts of out - just put the aggregate formula =ISERROR(...)&ISERROR(...) to any column row 2 you like.
Sample file: https://www.dropbox.com/s/qglyxmu3tkfxy7g/DataExtract2Cols.xlsx

Resources