Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show the column header to a row if there is value in cells of that columns without VBA

Tags:

excel

Update 1:

Because my question is not clear, so I post second example

Example 2

Because row 2, there is value 1 at Item 04 so the Get Item Name = Item 04. It is random and have a large number of columns (500).

The problem:

I would like to have a way to get a column header if there is any value input to the cells under that header. Please note that if at row 2 and column 1 has value, then other cell of row 2 will not have any value (other than 0).

It is hard to explain the problem in words so I have created an example.

Sample

like image 469
NCC Avatar asked Feb 17 '23 09:02

NCC


2 Answers

I posted a formula in the comments above, you may not have seen it. This is it:

=IF(COUNTA($B2:$D2)=0,"",INDEX($B$1:$D$1,MATCH(TRUE,INDEX($B2:$D2<>"",0),0)))

that will get the header for the first instance of a populated cell - if you have numeric values and want to ignore zeroes change to

=IF(COUNTA($B2:$D2)=0,"",INDEX($B$1:$D$1,MATCH(TRUE,INDEX($B2:$D2>0,0),0)))

Either way the formula can be extended to as large a range as you need

.....and if you have 500 columns you could use IFERROR to shorten a little

=IFERROR(INDEX($B$1:$D$1,MATCH(TRUE,INDEX($B2:$D2>0,0),0)),"")

like image 56
barry houdini Avatar answered Feb 20 '23 00:02

barry houdini


for a particular table which is relative small table with countable number of columns (i.e 3) try this

=IF(COUNTA(G8)>0,"Column 1",IF(COUNTA(H8)>0,"Column 2",IF(COUNTA(I8)>0,"Column 3",""))).  

my question is what if you have table contain 20 or 100 columns?

like image 44
TiTO Maro Avatar answered Feb 20 '23 00:02

TiTO Maro