How to sum values for similar text in a different column via VBA macro

Excel_Learner29

New Member
Joined
Apr 1, 2019
Messages
5
Hi Team,

I am looking some help on creating a macro which could help me sum values in column for B for similar text in col A and insert the sum field in col b for after every group its sums up and also insert a blank row after its sum the data

NamesValue
Apple25
Apple10
Orange10
Orange45
Milk20
Milk40

<tbody>
</tbody>



Macro to return :-

NamesValue
Apple25
Apple10
35
Orange10
Orange45
55
Milk20
Milk40
60

<tbody>
</tbody>
Appreciate your help
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Welcome to the Board!

Take a look at using Subtotals or Pivot Tables. Both of these should be able to do that for you without any need of VBA.
If you do Google Search, you will find some good tutorials on how to use these two Excel features.
 
Upvote 0
Hi ,
thank you for replying..but it would be a great help if the same can be achieved by a macro since this is going to be a re-occurring thing for me to do at office and also will be need to send in a format like this only and with involves a huge data...so will be little difficult to make pivot because i need data to be represented like above and not club them and give sum of one single value like pivot.

Would appreciate your help please.
 
Upvote 0
Did you take a look at what Subtotals produces?
It insert rows at changes like that automatically.
You can create the Subtotals from VBA with one simple line, i.e.
Code:
Sub InsertSubtotals()
    ActiveSheet.UsedRange.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(2), _
        Replace:=True, PageBreaks:=False, SummaryBelowData:=True
End Sub
 
Upvote 0
You are welcome!

Note that is just using the Subtotals method I proposed, but then just having VBA do it instead of you doing it manually.
A lot of times you can automate manual actions by turning on the Macro Recorder, and record yourself doing the steps manually (which will give you the VBA code to perform those functions).
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

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