Multiple columns of data on 1 row combined into multiple rows for identical value

jamobe

New Member
Joined
Dec 23, 2014
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Hi

Apologies if I have worded this wrong, I couldn't seem to find any help on the net regarding this method.

Basically I have 1 row of data as shown below

Rows.JPG


I would like to be able to have it transposed as below

Columns.JPG


I have many other columns inbetween the sku and Min Max prices, so not really after a formula that can transpose. I have attempted using the power query editor but I cannot get it to do as needed. I would like to be able to use the power query method rather than using VBA which is what the majority of posts I have stumbled upon recommend. So any help or advice on where I can learn how to apply this to my data would be great. Many Thanks!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi, any reason of not using VBA. That will be an easy approach.
 
Upvote 0
Hi



My table layout is shown below.



1612746161454.png


Load into Power Query Editor as shown below.

1612746189310.png








Remove unwanted columns 1 and 2 and the result is shown below.

1612746199535.png


Merge Min Price 1 and Max Price 1 with a delimiter

1612746214347.png


Repeat the process for other columns

1612746221942.png


Select Column SKU and Unpivot all Other Columns by going to Unpivot and select Other Columns options.
1612746245937.png




Remove Attribute column and split value column into two and rename the two columns.



1612746261694.png


Then load into your desired output location in your workbook.



1612746278912.png






Kind regards



Saba
 
Upvote 0
Solution
Another way using Power Query.

Book1
ABCDEFGHIJKLM
1SKUColumn1Column2Min Price1Max Price1Min Price2Max Price2Min Price3Max Price3SKUMin PriceMax Price
2SKU1SSAA510612712SKU1510
3SKU2SSAA48713813SKU1612
4SKU3SSAA354848SKU1712
5SKU248
6SKU2713
7SKU2813
8SKU335
9SKU348
10SKU348
Sheet3


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    RCC = Table.RemoveColumns(Source,{"Column1", "Column2"}),
    Unpivot = Table.UnpivotOtherColumns(RCC, {"SKU"}, "Attribute", "Value"),
    RemoveNum = Table.TransformColumns(Unpivot,{{"Attribute",each Text.Select(_,{"A".."Z","a".."z"," "})}}),
    Index = Table.AddIndexColumn(RemoveNum, "Index", 0, 1, Int64.Type),
    Int = Table.TransformColumns(Index,{{"Index", each Number.IntegerDivide(_,2)}}),
    Pivot = Table.Pivot(Int, List.Distinct(Int[Attribute]), "Attribute", "Value"),
    RC = Table.RemoveColumns(Pivot,{"Index"})
in
    RC
 
Upvote 0
Hi, any reason of not using VBA. That will be an easy approach.
Hi, I feel slightly more comfortable using power query for something like this, if I add or remove columns, any issues it would be easy to notice, if there is a way you can reference each column in VBA (not using a number) so if I moved any columns VBA would still pick up the correct data then I'd be very interested in that. As far as my VBA goes, I can only ever reference columns in a table by it's number ie .cells (1,20) I have struggled to find any way where I can simply use .cells (1, (Min Price)) basically just referencing the column header. Also, if using VBA to get this data onto a sheet, does it update automatically? Or does it require a refresh?
 
Upvote 0
This seems to do the trick with VBA and it updates automatically.

Book1
ABCDEFGHIJKLMN
1SKUColumn1Column2Min Price1Max Price1Min Price2Max Price2Min Price3Max Price3SKUMin PriceMax Price
2SKU1SSAA510612712SKU1510
3SKU2SSAA48713813SKU1612
4SKU3SSAA354848SKU1712
5SKU4SSAA51241539SKU248
6SKU5SSAA41528517SKU2713
7SKU2813
8SKU335
9SKU348
10SKU348
11SKU4512
12SKU4415
13SKU439
14SKU5415
15SKU528
16SKU5517
Sheet4


Standard Module
VBA Code:
Sub SKU()
Dim r As Range:         Set r = Range("A2:I" & Range("A" & Rows.Count).End(xlUp).Row)
Dim AR() As Variant:    AR = r.Value2

With CreateObject("System.Collections.ArrayList")
    For ro = 1 To UBound(AR)
        For col = 4 To UBound(AR, 2) Step 2
            If Not IsNull(AR(ro, col)) And Not IsNull(AR(ro, col + 1)) Then
                .Add Join(Array(AR(ro, 1), AR(ro, col), AR(ro, col + 1)), ";")
            End If
        Next col
    Next ro
    
    Range("L1").CurrentRegion.Clear
    Set r = Range("L1:N1")
    r.Value2 = Array("SKU", "Min Price", "Max Price")
    Set r = r.Offset(1).Resize(.Count, 1)
    r.Value = Application.Transpose(.toarray)
    r.TextToColumns DataType:=xlDelimited, Semicolon:=True
End With

End Sub

Worksheet Module
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long: LR = Range("A" & Rows.Count).End(xlUp).Row
Dim r As Range: Set r = Range("D" & LR & ":" & "I" & LR)
If Not Intersect(Target, r) Is Nothing Then
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
        SKU
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End If
End Sub
 
Upvote 0
If you have Excel 365 you can use dynamic array formulas.

Learning Sequences.xlsx
ABCDEFGHIJKLM
1SKUColumn1Column2Min Price1Max Price1Min Price2Max Price2Min Price3Max Price3SKUMin PriceMax Price
2SKU1SSAA510612712SKU1510
3SKU2SSAA48713813SKU1612
4SKU3SSAA354848SKU1712
5SKU4SSAA51241539SKU248
6SKU5SSAA41528517SKU2713
7SKU2813
8SKU335
9SKU348
10SKU348
11SKU4512
12SKU4415
13SKU439
14SKU5415
15SKU528
16SKU5517
Sheet4
Cell Formulas
RangeFormula
K2:M16K2=LET(tbl,Table1[[Min Price1]:[Max Price3]],r,ROWS(tbl), seq,SEQUENCE((r*COLUMNS(tbl))/2,,0), rs,INT((seq)/(3))+1, cs,((MOD(seq,3)+1)*2-2)+SEQUENCE(,2), u,INDEX(tbl,rs,cs),sk,Table1[SKU], ss,INDEX(sk,rs), xt,CHOOSE({1,1,2},u,ss), INDEX(xt,seq+1,{3,1,2}))
Dynamic array formulas.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

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