Vlookup or?

TrinaT

New Member
Joined
Mar 23, 2022
Messages
14
Office Version
  1. 365
Platform
  1. MacOS
I have a spreadsheet of data that is coming from an event registration software. Along with event registrations, people are able to purchase products. Unfortunately the data export pulls the product sales out in different columns (not the same column for each product), and displays in random order. It also pulls through blank columns randomly.

I'm trying to pull the data into a useable order so I can easily decipher who has ordered what, and pull out overall order quantities for the final orders.

I'm not even sure if this can be done. I've attached an image of how the data pulls out.
Screen Shot 2022-03-23 at 12.27.48 pm.png
 
You have MacOS 365 which means you should have power query.
Are you happy to get it to this point (see below) ?
If you are then I can either give you the Power Query code or we can do it in VBA ?


20220323 Transpose Data TrinaT.xlsm
ABCDE
13First NameLast NameItemCostQty
14JoeBlogsCooler101
15JoeBlogsShirt601
16JoeBlogsShirt 2401
17BarryEnglishBag301
18DanaDrinkCooler101
19DanaDrinkShirt601
20DanaDrinkShirt 2401
Sheet1
This is great! Yes that format is perfect!
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
To get a list of all items ordered & how many, you could use
+Fluff 1.xlsm
ABCDEFGHIJKLMNOPQRSTUVW
1First NameLast NameItem 1CostQtyItem 2CostQtyItem 3CostQtyItem 4Cost QtyItem 5Cost QtyItem 6Cost QtyItem 7Cost Qty
2JoeBlogsCooler101Shirt601Shirt 2401
3BarryEnglishBag301
4DanaDrinkCooler102Shirt601Shirt 2401
5
6
7
8
9
10Cooler3
11Shirt2
12Shirt 22
13Bag1
14
Main
Cell Formulas
RangeFormula
A10:A13A10=LET(rng,C2:W8,r,ROWS(rng),s,SEQUENCE(r*COLUMNS(rng)/3,,0),i,INDEX(rng,MOD(s,r)+1,INT(s/r)*3+1),UNIQUE(FILTER(i,i<>"")))
B10:B13B10=SUMIFS(E2:W8,C2:U8,A10#)
Dynamic array formulas.
Awesome thanks!
 
Upvote 0
Did you want to use Fluff's solution or did you still want to have a Power Query or VBA solution ?
 
Upvote 0
Awesome thanks!
Hmm, I thought you were after something quite different. :oops:

In your sample, for every order the Qty is 1 so it is not clear what the 'Cost' cells represent. If 2 Coolers were ordered, would the Cost still show 10 (cost per item) or would it be 20 (total cost)?
 
Upvote 0
Hmm, I thought you were after something quite different. :oops:

In your sample, for every order the Qty is 1 so it is not clear what the 'Cost' cells represent. If 2 Coolers were ordered, would the Cost still show 10 or would it be 20?
Hi Peter, the cost would show $20 :)
 
Upvote 0
Hi Peter, the cost would show $20 :)
Thanks. It looks like you might leaning away from a formula solution but if you have the latest dynamic array functions (not everybody with 365 does) then you can now get the item list more directly.

TrinaT.xlsm
ABCDEFGHIJKLMNOPQRSTUVW
1First NameLast NameItem 1CostQtyItem 2CostQtyItem 3CostQtyItem 4Cost QtyItem 5Cost QtyItem 6Cost QtyItem 7Cost Qty
2JoeBlogsCooler101Shirt601Shirt 21203
3BarryEnglishBag301
4DanaDrinkCooler202Shirt601Shirt 2401
5
9
10Cooler330
11Shirt2120
12Shirt 24160
13Bag130
Sheet1 (2)
Cell Formulas
RangeFormula
A10:A13A10=UNIQUE(TRANSPOSE(TEXTSPLIT(TEXTJOIN("|",1,IF(ISTEXT(C2:W4),C2:W4,"")),"|")))
B10:B13B10=SUMIFS(E2:W8,C2:U8,A25#)
C10:C13C10=SUMIFS(D2:V8,C2:U8,A25#)
Dynamic array formulas.
 
Upvote 0
If you want to try using Power Query:

Start with converting your data into a table:
• Select any cell in your data range
• Either Insert > Table (3rd button from the left ) OR Ctrl + T
• Uncheck "My table has headers"

To make the table look like the original and not show Column 1, Column 2 etc, you can go to Table Design > Uncheck Header Row (about in the middle of the toolbar)

Then:
• Click on the tab Table Design and in the white box on the far left put in the table name tblSales

Now still with a cell in the Table Selected:

• Data > From Table Range
• in PQ > Home > Advanced Editor (3rd Button from the left
• Replace the code you find there with the code below
• Ideally give the query a meaningfull name (in the pane on the right)

Close & Load (will default to a new sheet) OR Close & Load To

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="tblSales"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Column1", "Column2"}, "Attribute", "Value"),
    #"Added Index" = Table.AddIndexColumn(#"Unpivoted Other Columns", "Index", 0, 1, Int64.Type),
    AddedLineGrp = Table.AddColumn(#"Added Index", "LineGroup", each Number.IntegerDivide([Index],3)),
    AddedColGrp = Table.AddColumn(AddedLineGrp, "ColumnOrder", each Number.Mod([Index],3)),
    #"Filtered Rows" = Table.SelectRows(AddedColGrp, each ([Column2] <> "Last Name")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Attribute", "Index"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns", {{"ColumnOrder", type text}}, "en-AU"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns", {{"ColumnOrder", type text}}, "en-AU")[ColumnOrder]), "ColumnOrder", "Value"),
    #"Sorted Rows" = Table.Sort(#"Pivoted Column",{{"LineGroup", Order.Ascending}}),
    #"Removed Columns LineGrp" = Table.RemoveColumns(#"Sorted Rows",{"LineGroup"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns LineGrp",{{"0", "Item"}, {"1", "Cost"}, {"2", "Qty"}, {"Column1", "First Name"}, {"Column2", "Last Name"}})
in
    #"Renamed Columns"
 
Upvote 0
If you want to try using Power Query:

Start with converting your data into a table:
• Select any cell in your data range
• Either Insert > Table (3rd button from the left ) OR Ctrl + T
• Uncheck "My table has headers"

To make the table look like the original and not show Column 1, Column 2 etc, you can go to Table Design > Uncheck Header Row (about in the middle of the toolbar)

Then:
• Click on the tab Table Design and in the white box on the far left put in the table name tblSales

Now still with a cell in the Table Selected:

• Data > From Table Range
• in PQ > Home > Advanced Editor (3rd Button from the left
• Replace the code you find there with the code below
• Ideally give the query a meaningfull name (in the pane on the right)

Close & Load (will default to a new sheet) OR Close & Load To

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="tblSales"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Column1", "Column2"}, "Attribute", "Value"),
    #"Added Index" = Table.AddIndexColumn(#"Unpivoted Other Columns", "Index", 0, 1, Int64.Type),
    AddedLineGrp = Table.AddColumn(#"Added Index", "LineGroup", each Number.IntegerDivide([Index],3)),
    AddedColGrp = Table.AddColumn(AddedLineGrp, "ColumnOrder", each Number.Mod([Index],3)),
    #"Filtered Rows" = Table.SelectRows(AddedColGrp, each ([Column2] <> "Last Name")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Attribute", "Index"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns", {{"ColumnOrder", type text}}, "en-AU"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns", {{"ColumnOrder", type text}}, "en-AU")[ColumnOrder]), "ColumnOrder", "Value"),
    #"Sorted Rows" = Table.Sort(#"Pivoted Column",{{"LineGroup", Order.Ascending}}),
    #"Removed Columns LineGrp" = Table.RemoveColumns(#"Sorted Rows",{"LineGroup"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns LineGrp",{{"0", "Item"}, {"1", "Cost"}, {"2", "Qty"}, {"Column1", "First Name"}, {"Column2", "Last Name"}})
in
    #"Renamed Columns"
Thanks Alex, I don't have advanced editor on mac version, will swap to a Windows version later and complete from there :)
 
Upvote 0
To rearrange the original data as in post #9 (no collating of similar people and/or items ordered) you could also consider this macro approach.

VBA Code:
Sub Rearrange()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long, uba2 As Long
  
  a = Range("A1").CurrentRegion.Value
  uba2 = UBound(a, 2)
  ReDim b(1 To Rows.Count, 1 To 5)
  For i = 2 To UBound(a)
    For j = 3 To uba2 Step 3
      If Len(a(i, j)) > 0 Then
        k = k + 1
        b(k, 1) = a(i, 1): b(k, 2) = a(i, 2): b(k, 3) = a(i, j): b(k, 4) = a(i, j + 1): b(k, 5) = a(i, j + 2)
      End If
    Next j
  Next i
  Application.ScreenUpdating = False
  With Range("A" & UBound(a) + 4).Resize(k, 5)
    .Value = b
    .Rows(0).Value = Array("First Name", "Last Name", "Item", "Cost", "Qty")
  End With
  Application.ScreenUpdating = True
End Sub

So for original data as in rows 1:4 below, the code has produced the values in row 7 onwards.

TrinaT.xlsm
ABCDEFGHIJKLMNOPQRSTUVW
1First NameLast NameItem 1CostQtyItem 2CostQtyItem 3CostQtyItem 4Cost QtyItem 5Cost QtyItem 6Cost QtyItem 7Cost Qty
2JoeBlogsCooler101Shirt601Shirt 21203
3BarryEnglishBag301
4DanaDrinkCooler202Shirt601Shirt 2401
5
6
7First NameLast NameItemCostQty
8JoeBlogsCooler101
9JoeBlogsShirt601
10JoeBlogsShirt 21203
11BarryEnglishBag301
12DanaDrinkCooler202
13DanaDrinkShirt601
14DanaDrinkShirt 2401
Rearrange
 
Upvote 0

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

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