I need to invert a table

ffinlay

New Member
Joined
Mar 2, 2017
Messages
4
Office Version
  1. 365
Platform
  1. Windows
First, Thank you for this forum. I've followed it for a few years and everyone here has been very helpful. This is the first time I've not been able to find a solution to a problem.

I need to "invert" a table. I'd thought about doing it with some 2-d lookups, but most on here are numeric based and only work with a single instance within a table. Mine is a text only table, and too big to do by hand.

Say I have a table like below:

aapplescranberriespears
bpearsapplesorangeslemons
ccranberriesorangeslemons
dapples
elemonspears
fappleslemonspears
gnutsapplesoranges

<colgroup><col><col span="5"></colgroup><tbody>
</tbody>


What I need is the column 1 value beside each of the item types. If there are more than one, I need each of them in their own column:

applesabdfg
cranberriesac
pearsabef
orangesbcg
lemonsbcef
nutsg

<colgroup><col><col span="5"></colgroup><tbody>
</tbody>


I can do this in VBA or as macros/formulas; I really don't care. The real table is very large with about 21K items in the original table with about 3000 rows.

Any ideas would be greatly appreciated.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
maybe something like...

Unknown
ABCDEF
1aapplescranberriespears
2bpearsapplesorangeslemons
3ccranberriesorangeslemons
4dapples
5elemonspears
6fappleslemonspears
7gnutsapplesoranges
8
9applesabdfg
10cranberriesac
11pearsabef
12orangesbcg
13lemonsbcef
14nutsg

<tbody>
</tbody>
Sheet1

Array Formulas
CellFormula
B9{=IFERROR(INDEX($A$1:$A$7,SMALL(IF($B$1:$F$7=$A9,ROW($A$1:$A$7)-ROW($A$1)+1),COLUMNS($B9:B9))),"")}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0
That is awesome. I've tried array formulas before, but am not all that experienced with them. The expanding search array using the columns function is pretty interesting. I'd like to understand though, what does the Small() function provide in this solution?
 
Upvote 0

Forum statistics

Threads
1,215,128
Messages
6,123,206
Members
449,090
Latest member
bes000

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