Combining a table of data into summarised lines

TheRedCardinal

Board Regular
Joined
Jul 11, 2019
Messages
243
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I've tried to solve this myself but I've now hit a brick wall.

I have a table of data with 12 columns and multiple rows that vary.

I want to split that table out into two workbooks depending on the value of the content of column 5 - which will either be "Payable or Receivable"

I then want to condense all lines which have the same reference in column 2 into a single line, maintaining all the other data (which is text and so identical) except the values in columns 7 8 and 9 which I need to sum up.

I've attempted a summary here (I've removed some columns for the sake of the visual)

1587661415880.png
1587661415880.png


I started with this, which was to create a dictionary containing unique values.

VBA Code:
Set SalesObjDict = CreateObject("Scripting.Dictionary")
Set PurchObjDict = CreateObject("Scripting.Dictionary")
Set Wbk1 = ThisWorkbook
Set WS1 = Wbk1.Sheets("Results")

ResultsArray = WS1.Range("Data")

For Counter = 2 To UBound(ResultsArray)

    If ResultsArray(Counter, 5) = "VAT payable" Then
    
        SalesObjDict(ResultsArray(Counter, 2)) = 1
    
    Else
    
        PurchObjDict(ResultsArray(Counter, 2)) = 1
    
    End If

Next Counter

End Sub

This worked well and I have 2 dictionaries containing unique values.

But now I am not sure where to go....?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
If you use XL2BB to post your sample file, I am sure that those here can offer up several options to achieve your expected results.
 
Upvote 0
Hi there,

Why not use Power Query for this? You would need two queries, one for each desired output. You wouldn't quite get what you're asking for, as columns 1 and 3 (Date and Source) do not contain unique values by Voucher.

Assuming your data is in a Table, further the Table is named "tData", your queries would look like this...

qPayable
Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="tData"]}[Content],
    #"TypeColumns" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Voucher", Int64.Type}, {"Source", type text}, {"VAT code", type text}, {"VAT direction", type text}, {"Name", type text}, {"Amounts", Int64.Type}, {"Origin", Int64.Type}, {"Other1", Int64.Type}, {"Other2", Int64.Type}}),
    #"Filter" = Table.SelectRows(#"TypeColumns", each ([VAT direction] = "VAT payable")),
    #"Group" = Table.Group(#"Filter", {"Voucher", "VAT code", "VAT direction", "Name"}, {{"Amount_Sum", each List.Sum([Amounts]), type number}, {"Origin_Sum", each List.Sum([Origin]), type number}, {"Other1_Sum", each List.Sum([Other1]), type number}, {"Other2_Sum", each List.Sum([Other2]), type number}})
in
    #"Group"

qReceivable
Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="tData"]}[Content],
    #"TypeColumns" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Voucher", Int64.Type}, {"Source", type text}, {"VAT code", type text}, {"VAT direction", type text}, {"Name", type text}, {"Amounts", Int64.Type}, {"Origin", Int64.Type}, {"Other1", Int64.Type}, {"Other2", Int64.Type}}),
    #"Filter" = Table.SelectRows(#"TypeColumns", each ([VAT direction] = "VAT receivable")),
    #"Group" = Table.Group(#"Filter", {"Voucher", "VAT code", "VAT direction", "Name"}, {{"Amount_Sum", each List.Sum([Amounts]), type number}, {"Origin_Sum", each List.Sum([Origin]), type number}, {"Other1_Sum", each List.Sum([Other1]), type number}, {"Other2_Sum", each List.Sum([Other2]), type number}})
in
    #"Group"

They're almost identical, of course. Load them to Tables, connection, whatever. You can even export the data connection as a file.

Is this still something you want VBA for?
 
Upvote 0
Thanks!
Power Queries are not something I'm familiar with... I'll look them up! They sound interesting and useful.
 
Upvote 0
Edit: Of course I forgot Jon's post lol. Thanks Alan.

You should definitely look into Power Query. It's one of the most powerful tools ever put into Excel. There's a bit of a learning curve but you'll find many good resources online for it. Below are some resources to get you started.

Websites

Videos
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,462
Members
448,965
Latest member
grijken

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