Get Column Header from each rows item

Approyale

New Member
Joined
Jan 16, 2018
Messages
3
Hi

For every row with the value, fetch the table header.

I have the following table:

ABCD
1xx
2xxx
3
4xx

<tbody>
</tbody>

Desired Result:
1A
1B
2B
2C
2D
4A
4D

<tbody>
</tbody>

Thank you in advance.

Best,
AppRoyale
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
this should do it:
Code:
Sub test2()

inarr = Range(Cells(1, 1), Cells(5, 5))
Range(Cells(1, 10), Cells(30, 11)) = ""
outarr = Range(Cells(1, 10), Cells(30, 11))
indi = 1
For i = 2 To 5
 For j = 2 To 5
  If inarr(i, j) = "x" Then
  outarr(indi, 1) = inarr(i, 1)
  outarr(indi, 2) = inarr(1, j)
  indi = indi + 1
  End If
 Next j
Next i
Range(Cells(1, 10), Cells(30, 11)) = outarr


End Sub
 
Last edited:
Upvote 0
this should do it:
Code:
Sub test2()

inarr = Range(Cells(1, 1), Cells(5, 5))
Range(Cells(1, 10), Cells(30, 11)) = ""
outarr = Range(Cells(1, 10), Cells(30, 11))
indi = 1
For i = 2 To 5
 For j = 2 To 5
  If inarr(i, j) = "x" Then
  outarr(indi, 1) = inarr(i, 1)
  outarr(indi, 2) = inarr(1, j)
  indi = indi + 1
  End If
 Next j
Next i
Range(Cells(1, 10), Cells(30, 11)) = outarr


End Sub
Thank you. I suppose that the result can not be achieved by an Ecel formula only?
 
Upvote 0
Very difficult because in your example the number of rows need for the "1" s is two rows, but if you add an x in then this becaomse 3 rows and every thing shifts down I can't see how you can do that with worksheet functions alone
 
Upvote 0
A possible solution using formulas


A
B
C
D
E
F
1
A​
B​
C​
D​
2
1​
x​
x​
3
2​
x​
x​
x​
4
3​
5
4​
x​
x​
6
7
Desired Result:​
8
1​
A​
9
1​
B​
10
2​
B​
11
2​
C​
12
2​
D​
13
4​
A​
14
4​
D​
15

Array formula in A8 copied down
=IFERROR(INDEX(A$2:A$5,MATCH(ROWS(A$8:A8)-1,COUNTIF(OFFSET(B$1:E$1,,,ROW(B$1:E$5)-ROW(B$1)+1),"x")),1),"")
Ctrl+Shift+Enter

Array formula in B8 copied down
=IF(A8="","",INDEX($B$1:$E$1,SMALL(IF(INDEX($B$2:$E$5,MATCH(A8,A$2:A$5,0),0)="x",COLUMN($B$1:$E$1)-COLUMN($B$1)+1),COUNTIF(A$8:A8,A8))))
Ctrl+Shift+Enter

M.
 
Upvote 0
It is always nice to be proved wrong, I learn something every day!!
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top