Sum rows based on Column value - VBA

galliena

New Member
Joined
Mar 1, 2014
Messages
8
Hello,

Does anyone now how I can sum rows based on columns values using vba?

For example,

Name Salary

Felipe 800

Ricardo 1000

Felipe 800

It would become,

Name Salary

Felipe 1600

Ricardo 1000
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi!

why dont you use a simple =sumif(A1:A3;"Felipe";B1:B3)

You could also replace "Felipe" with C1 for example and insert a drop down menu based on your names.

Cheers,
Forb
 
Upvote 0
Hello!


I guess that I need to explain better, I do not know what will have in the name filed.

So I need to create a macro that can recognize the names and sum the ones that are equal.
 
Upvote 0
does your data start in A1?


Code:
Sub AddTogether()
With ThisWorkbook.PivotCaches.Create(xlDatabase, Range("A1").CurrentRegion).CreatePivotTable(Range("E2"), "PivotNameSalary")
    .PivotFields("Name").Orientation = xlRowField
    .AddDataField .PivotFields("Salary"), "Sum Of Salary", xlSum
    .ColumnGrand = False
    .RowGrand = False
    .RowAxisLayout xlTabularRow
End With
End Sub
 
Upvote 0
Ok, this an good solution, do you know if there is any buit-in way to do this besides of the pivot table?
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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