I have a sheet with a table, where I want to extract the header of the max value in each row. The simple solution for that is:
=IFERROR(IF(AND(B2<>"Sa",B2<>"Su"),INDEX($C$1:$Y$1,MATCH(MAX(C2:Y2),C2:Y2,0)),"weekend"),"")
Problem is, that if you insert a column to the right on column Y, the formula will not change the range (it will still be C2:Y2, and data on column Z will not be included). For that I created this formula, which solves this issue:
=iferror(if(AND(B2<>"la";B2<>"su");INDEX($C$1:$1;MATCH(MAX(INDIRECT("C"&row()&":"&SUBSTITUTE(ADDRESS(1;MATCH(OFFSET(INDIRECT(ADDRESS(1;COLUMN()));0;-5);$1:$1;0)-1;4);1;"")&row()));INDIRECT("C"&row()&":"&SUBSTITUTE(ADDRESS(1;MATCH(OFFSET(INDIRECT(ADDRESS(1;COLUMN()));0;-5);$1:$1;0)-1;4);1;"")&row());0));"w");"")
I was wondering: is there an easier/simpler way to do this with google sheets formulas? Basically I want the range to be from C1:<whatever letter is before the Total column>.
Thanks!