Transpose several two-column groups of information into a single vertical two-column list

Tiv

New Member
Joined
Dec 9, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I was sent a spreadsheet, but reading the information is difficult in a horizontal format. It needs to be vertical. I need to be able to transpose it, but I need it to be in a two-column formation.

The information came to me like this:
PartQtyPartQtyPartQtyPartQty
Aisle 1Bananas
1​
Oranges
2​
Apples
9​
Raspberries
50​
Aisle 2Blueberries
16​
Mangos
7​
Potatoes
10​
Carrots
12​
Aisle 3Green beans
72​
Lima beans
100​
Onions
37​
Celery
9​




I need it to look like this:
Aisle 1
Bananas
1​
Oranges
2​
Apples
9​
Raspberries
50​
Aisle 2
Blueberries
16​
Mangos
7​
Potatoes
10​
Carrots
12​
Aisle 3
Green beans
72​
Lima beans
100​
Onions
37​
Celery
9​



I'm not having any luck with the Transpose function unless there's more to the formula.

How do I turn several two-column-bits of information in a horizontal format into a vertical two-column list?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Tiv, Well let's get the ball rollin. Now I know you asked for a Transpose function, and I came up with a vba program. At least this should work, and we need to start some place. If you have any questions, comments or suggestions let us know. Now sometimes, the A plus students will weigh in and do the same thing this program does but they will do it with 2 lines of code. Anyway, let the discussion begin.

VBA Code:
Sub Prog1()

Dim Row1 As Long
Dim Col1 As Long
Dim RowCnt As Long
Dim ColCnt As Long

Sheets("Complete").Cells.ClearContents

Sheets("Data").Select
Row1 = 2
Col1 = 1
a = 1

RowCnt = Cells(Rows.Count, "A").End(xlUp).Row
ColCnt = Cells(1, Columns.Count).End(xlToLeft).Column

Sheets("Complete").Cells(1, 1) = Cells(2, 1) '.Select

For i = 2 To RowCnt

For a = 2 To ColCnt

If Col1 = 1 Then
    Sheets("Complete").Cells(Row1, Col1) = Cells(i, a) '.Select
    Col1 = Col1 + 1
Else
    Sheets("Complete").Cells(Row1, Col1) = Cells(i, a) '.Select
    Col1 = 1
    Row1 = Row1 + 1
End If

Next a

Sheets("Complete").Cells(Row1 + 1, Col1) = Cells(i + 1, 1)
Row1 = Row1 + 2
Next i

Sheets("Complete").Select
Sheets("Complete").Range("A1").Select

End Sub

22-12-07 work 3.xlsm
AB
1Aisle 1
2Bananas1
3Oranges2
4Apples9
5Raspberries50
6
7Aisle 2
8Blueberries16
9Mangos7
10Potatoes10
11Carrots12
12
13Aisle 3
14Green beans72
15Lima beans100
16Onions37
17Celery9
Complete


22-12-07 work 3.xlsm
ABCDEFGHI
1PartQtyPartQtyPartQtyPartQtyPart
2Aisle 1Bananas1Oranges2Apples9Raspberries50
3Aisle 2Blueberries16Mangos7Potatoes10Carrots12
4Aisle 3Green beans72Lima beans100Onions37Celery9
Data
 
Upvote 0
Tiv, Well let's get the ball rollin. Now I know you asked for a Transpose function, and I came up with a vba program. At least this should work, and we need to start some place. If you have any questions, comments or suggestions let us know. Now sometimes, the A plus students will weigh in and do the same thing this program does but they will do it with 2 lines of code. Anyway, let the discussion begin.

VBA Code:
Sub Prog1()

Dim Row1 As Long
Dim Col1 As Long
Dim RowCnt As Long
Dim ColCnt As Long

Sheets("Complete").Cells.ClearContents

Sheets("Data").Select
Row1 = 2
Col1 = 1
a = 1

RowCnt = Cells(Rows.Count, "A").End(xlUp).Row
ColCnt = Cells(1, Columns.Count).End(xlToLeft).Column

Sheets("Complete").Cells(1, 1) = Cells(2, 1) '.Select

For i = 2 To RowCnt

For a = 2 To ColCnt

If Col1 = 1 Then
    Sheets("Complete").Cells(Row1, Col1) = Cells(i, a) '.Select
    Col1 = Col1 + 1
Else
    Sheets("Complete").Cells(Row1, Col1) = Cells(i, a) '.Select
    Col1 = 1
    Row1 = Row1 + 1
End If

Next a

Sheets("Complete").Cells(Row1 + 1, Col1) = Cells(i + 1, 1)
Row1 = Row1 + 2
Next i

Sheets("Complete").Select
Sheets("Complete").Range("A1").Select

End Sub

22-12-07 work 3.xlsm
AB
1Aisle 1
2Bananas1
3Oranges2
4Apples9
5Raspberries50
6
7Aisle 2
8Blueberries16
9Mangos7
10Potatoes10
11Carrots12
12
13Aisle 3
14Green beans72
15Lima beans100
16Onions37
17Celery9
Complete


22-12-07 work 3.xlsm
ABCDEFGHI
1PartQtyPartQtyPartQtyPartQtyPart
2Aisle 1Bananas1Oranges2Apples9Raspberries50
3Aisle 2Blueberries16Mangos7Potatoes10Carrots12
4Aisle 3Green beans72Lima beans100Onions37Celery9
Data
Tiv, Well let's get the ball rollin. Now I know you asked for a Transpose function, and I came up with a vba program. At least this should work, and we need to start some place. If you have any questions, comments or suggestions let us know. Now sometimes, the A plus students will weigh in and do the same thing this program does but they will do it with 2 lines of code. Anyway, let the discussion begin.

VBA Code:
Sub Prog1()

Dim Row1 As Long
Dim Col1 As Long
Dim RowCnt As Long
Dim ColCnt As Long

Sheets("Complete").Cells.ClearContents

Sheets("Data").Select
Row1 = 2
Col1 = 1
a = 1

RowCnt = Cells(Rows.Count, "A").End(xlUp).Row
ColCnt = Cells(1, Columns.Count).End(xlToLeft).Column

Sheets("Complete").Cells(1, 1) = Cells(2, 1) '.Select

For i = 2 To RowCnt

For a = 2 To ColCnt

If Col1 = 1 Then
    Sheets("Complete").Cells(Row1, Col1) = Cells(i, a) '.Select
    Col1 = Col1 + 1
Else
    Sheets("Complete").Cells(Row1, Col1) = Cells(i, a) '.Select
    Col1 = 1
    Row1 = Row1 + 1
End If

Next a

Sheets("Complete").Cells(Row1 + 1, Col1) = Cells(i + 1, 1)
Row1 = Row1 + 2
Next i

Sheets("Complete").Select
Sheets("Complete").Range("A1").Select

End Sub

22-12-07 work 3.xlsm
AB
1Aisle 1
2Bananas1
3Oranges2
4Apples9
5Raspberries50
6
7Aisle 2
8Blueberries16
9Mangos7
10Potatoes10
11Carrots12
12
13Aisle 3
14Green beans72
15Lima beans100
16Onions37
17Celery9
Complete


22-12-07 work 3.xlsm
ABCDEFGHI
1PartQtyPartQtyPartQtyPartQtyPart
2Aisle 1Bananas1Oranges2Apples9Raspberries50
3Aisle 2Blueberries16Mangos7Potatoes10Carrots12
4Aisle 3Green beans72Lima beans100Onions37Celery9
Data
Thanks! I've got to learn VBA. :) That's a much more elegant solution to what I did.

I managed to mull it out, sort of, using an Xlookup formula. It ended up with the Aisle being at the top of the list, the part and the quantity being listed below. I'm going to try your solution to see how it works.
 
Upvote 0
Tiv it is good to hear from you. The folks on this web site are very helpful. If you have any questions on how things work or what you need to do to make things work, just ask. My one suggestion is to download XL2BB software so you can work on your excel problems.
 
Upvote 0
If this presentation works for you then power query may be the answer

Column1ValueQty
Aisle 1Bananas1
Aisle 1Oranges2
Aisle 1Apples9
Aisle 1Raspberries50
Aisle 2Blueberries16
Aisle 2Mangos7
Aisle 2Potatoes10
Aisle 2Carrots12
Aisle 3Green beans72
Aisle 3Lima beans100
Aisle 3Onions37
Aisle 3Celery9


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Column1"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Qty", each if Text.StartsWith([Attribute], "Qty") then [Value] else null),
    #"Filled Up" = Table.FillUp(#"Added Custom",{"Qty"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Up", each not Text.StartsWith([Attribute], "Qty")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Attribute"})
in
    #"Removed Columns"
 
Upvote 0
Tiv it is good to hear from you. The folks on this web site are very helpful. If you have any questions on how things work or what you need to do to make things work, just ask. My one suggestion is to download XL2BB software so you can work on your excel problems.
I've never heard of XL2BB software. What is it exactly?
 
Upvote 0
Xlookup does not exist in xl2010, so is your profile correct?
We've upgraded to Office 365 now. I've fallen in love with the Xlookup formula. I've always loved the Vlookup and the index/match, but I think I'm definitely a convert to the Xlookup function. :)
 
Upvote 0
If this presentation works for you then power query may be the answer

Column1ValueQty
Aisle 1Bananas1
Aisle 1Oranges2
Aisle 1Apples9
Aisle 1Raspberries50
Aisle 2Blueberries16
Aisle 2Mangos7
Aisle 2Potatoes10
Aisle 2Carrots12
Aisle 3Green beans72
Aisle 3Lima beans100
Aisle 3Onions37
Aisle 3Celery9


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Column1"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Qty", each if Text.StartsWith([Attribute], "Qty") then [Value] else null),
    #"Filled Up" = Table.FillUp(#"Added Custom",{"Qty"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Up", each not Text.StartsWith([Attribute], "Qty")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Attribute"})
in
    #"Removed Columns"
I've got to learn VBA. I've been using spreadsheets since Lotus 123, but I've never had a chance to learn VBA.
 
Upvote 0
I've never heard of XL2BB software. What is it exactly?
An add-in that allows you to port Excel snippets easily into this message board (like alansidman did).

I will highly recommend going for alansidman's solution, as this structure allows you to do much more with your data later on. And it is based on Power Query, not VBA (and is much easier to learn).
 
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,161
Members
452,615
Latest member
bogeys2birdies

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