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
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,670
Office Version
  1. 2010
Platform
  1. Windows
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:

Approyale

New Member
Joined
Jan 16, 2018
Messages
3
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?
 

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,670
Office Version
  1. 2010
Platform
  1. Windows
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
 

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,414

ADVERTISEMENT

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.
 

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
1,670
Office Version
  1. 2010
Platform
  1. Windows
It is always nice to be proved wrong, I learn something every day!!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,488
Messages
5,601,975
Members
414,487
Latest member
inxlsplot

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
Top