VBA / Macro that Matches Names and then Sums their Amount

sleepysheep72

New Member
Joined
Dec 21, 2021
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hello :) I am not a native english speaker so I'm sorry if I make grammar mistakes
I have this question in the exam sheet I'm doing and it's making my head hurt. How do I get to match the names in column C and column F and then add both amounts?

Mini-sheet for reference
Exam-Excel.xlsb
CDEFG
4NameAmountNameAmount
5Robert10,000.00Eya50,000.00
6Chloe30,000.00Alyanna40,000.00
7Amber50,000.00Robert30,000.00
8Eya23,500.00Chloe25,000.00
9Alyanna53,200.00Amber34,000.00
VBA Test
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
If I were doing this, I would use Power Query. More simpler than using VBA.

Book6
ABCDEFGH
1NameAmountNameAmountNameTotal
2Robert10,000.00Eya50,000.00Robert40000
3Chloe30,000.00Alyanna40,000.00Chloe55000
4Amber50,000.00Robert30,000.00Amber84000
5Eya23,500.00Chloe25,000.00Eya73500
6Alyanna53,200.00Amber34,000.00Alyanna93200
Sheet1


Power Query:
let
    Source = Table.Combine({Table1, Table2}),
    #"Grouped Rows" = Table.Group(Source, {"Name"}, {{"Total", each List.Sum([Amount]), type nullable number}})
in
    #"Grouped Rows"
 
Upvote 0
Hi
VBA
Try
VBA Code:
Sub test()
    lr = Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    a = Sheets("sheet1").Cells(1, 1).Resize(lr, 2)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If Not .exists(a(i, 1)) Then .Add a(i, 1), a(i, 2)
        Next
        a = Sheets("sheet1").Cells(1, 4).Resize(lr, 2)
        For i = 2 To UBound(a)
            If .exists(a(i, 1)) Then
                x = .Item(a(i, 1)): x = x + a(i, 2): .Item(a(i, 1)) = x
            End If
        Next
        Sheets("sheet1").Cells(1, 7).Resize(.Count, 2) = Application.Index(Application.Transpose(Array(.keys, .items)), 0, 0)
    End With
End Sub
 
Upvote 0
No need for a macro, you can use the sumifs function to add the amounts for each person.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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