Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find last non-zero cell's column reference in an UNORDERED range of values

I have a range with numbers in a row in Excel, say:

          A  B  C  D  E  F  G  H  I  J  K  L
Line 1 => 0  0  0  3  2  8  3  6  0  0  0  0

All cells are non-blank but some contain zeros and some contain numbers. Also, the range cannot be ordered in either ascending or descending order.

I need a formula (not VBA) that will return the column of the last non-zero value in the range (i.e. column 8 for cell H1 above). I can get the actual value of cell H1 with this formula:

 LOOKUP(2,1/(A1:A10<>0),A1:A10)  

but I cannot find a way to get the column number for that cell.

Any ideas?

like image 332
AHa Avatar asked Sep 11 '15 15:09

AHa


People also ask

How do you find the last non blank cell in a row?

Return the row number of the last non blank cell: Enter the formula: =SUMPRODUCT(MAX((A2:A20<>"")*ROW(A2:A20))) into a blank cell to locate the calculated result, and then press Enter key to return the correct result, see screenshot: Note: In the above formulas, A2:A20 is the range of cells that you want to use.

How do you find the last filled cell?

Locate the last cell that contains data or formatting on a worksheet. To locate the last cell that contains data or formatting, click anywhere in the worksheet, and then press CTRL+END.


2 Answers

You are very close:

=LOOKUP(2,1/(A1:L1<>0),COLUMN(A1:L1))
like image 185
Ron Rosenfeld Avatar answered Nov 14 '22 21:11

Ron Rosenfeld


Enter

=MAX(IF(YourRange=0,0,COLUMN(YourRange)))

as an array formula (CTRL-SHIFT-ENTER).

like image 34
xidgel Avatar answered Nov 14 '22 22:11

xidgel