简体   繁体   中英

Column name of last non zero value in row in Excel

How I can get column name of last non zero value in row, using Excel functions.

Example:

A:E - columns with values x - function result

A B C D E x

0 0 1 0 0 C
1 0 2 1 2 E
0 1 1 0 1 E
1 1 1 1 1 E
0 0 0 0 0 

This works:

=IFERROR(CHAR(AGGREGATE(14,6,COLUMN(A1:E1)/(A1:E1<>0),1)+64),"")

在此处输入图片说明

These are array-formulas that must be entered using CTRL + SHIFT + ENTER :

This works up to ZZ:

=IFERROR(SUBSTITUTE(MID(CELL("address",OFFSET(A1,0,MAX(IF(A1:AA1<>0,COLUMN(A1:AA1),0))-1)),2,2),"$",""),"")

This works for all columns:

=IFERROR(MID(CELL("address",OFFSET(A1,0,MAX(IF(A1:AAA1<>0,COLUMN(A1:AAA1),0))-1)),2,FIND("$",MID(CELL("address",OFFSET(A1,0,MAX(IF(A1:AAA1<>0,COLUMN(A1:AAA1),0))-1)),2,99))-1),"")

Update: The accepted answer is more efficient. It assumes numeric values but could be easily updated to handle non-numeric values as well. However it could be optimised further:

=IFERROR(MID(SUBSTITUTE(ADDRESS(1,MAX(IF(A2:XED2,COLUMN(A2:XED2)))),"$1",""),2,3),"")

Enter with CTRL + Shift + Enter :

=IFERROR(MID(ADDRESS(ROW(),MAX(IF(A2:E2,COLUMN(A2:E2)))),2,SEARCH("$",ADDRESS(ROW(),MAX(IF(A2:E2,COLUMN(A2:E2)))),2)-2),"")

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM