vba macro to sum by group

viva0521

New Member
Joined
Jul 6, 2015
Messages
7
Hey there,

suppose I have a table like this:

[TABLE="width: 320"]
<colgroup><col width="64" span="5" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64, align: center"]V[/TD]
[TD="width: 64, align: center"]From[/TD]
[TD="width: 64, align: center"]To[/TD]
[TD="width: 64, align: center"]index[/TD]
[TD="width: 64, align: center"]decision[/TD]
[/TR]
[TR]
[TD="align: center"]v1[/TD]
[TD="align: center"]D1[/TD]
[TD="align: center"]A1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[/TR]
[TR]
[TD="align: center"]v2[/TD]
[TD="align: center"]D1[/TD]
[TD="align: center"]A1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[/TR]
[TR]
[TD="align: center"]v3[/TD]
[TD="align: center"]D1[/TD]
[TD="align: center"]A1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[/TR]
[TR]
[TD="align: center"]v4[/TD]
[TD="align: center"]D2[/TD]
[TD="align: center"]A2[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[/TR]
[TR]
[TD="align: center"]v5[/TD]
[TD="align: center"]D2[/TD]
[TD="align: center"]A2[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[/TR]
[TR]
[TD="align: center"]v6[/TD]
[TD="align: center"]D2[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"][/TD]
[TD="align: center"]no ship[/TD]
[/TR]
[TR]
[TD="align: center"]v7[/TD]
[TD="align: center"]D2[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"][/TD]
[TD="align: center"]no ship[/TD]
[/TR]
[TR]
[TD="align: center"]v8[/TD]
[TD="align: center"]D3[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"][/TD]
[TD="align: center"]no ship[/TD]
[/TR]
[TR]
[TD="align: center"]v9[/TD]
[TD="align: center"]D3[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[/TR]
[TR]
[TD="align: center"]v10[/TD]
[TD="align: center"]D3[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[/TR]
</tbody>[/TABLE]

how can i create a macro to sum up by group (from, to , index) like following:

[TABLE="width: 384"]
<colgroup><col width="64" span="6" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64, align: center"]V[/TD]
[TD="width: 64, align: center"]From[/TD]
[TD="width: 64, align: center"]To[/TD]
[TD="width: 64, align: center"]index[/TD]
[TD="width: 64, align: center"]decision[/TD]
[TD="width: 64, align: center"]# of ship[/TD]
[/TR]
[TR]
[TD="align: center"]v1[/TD]
[TD="align: center"]D1[/TD]
[TD="align: center"]A1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]v2[/TD]
[TD="align: center"]D1[/TD]
[TD="align: center"]A1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]v3[/TD]
[TD="align: center"]D1[/TD]
[TD="align: center"]A1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]v4[/TD]
[TD="align: center"]D2[/TD]
[TD="align: center"]A2[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]v5[/TD]
[TD="align: center"]D2[/TD]
[TD="align: center"]A2[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]v6[/TD]
[TD="align: center"]D2[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"][/TD]
[TD="align: center"]no ship[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]v7[/TD]
[TD="align: center"]D2[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"][/TD]
[TD="align: center"]no ship[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]v8[/TD]
[TD="align: center"]D3[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"][/TD]
[TD="align: center"]no ship[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]v9[/TD]
[TD="align: center"]D3[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]v10[/TD]
[TD="align: center"]D3[/TD]
[TD="align: center"]A3[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]ship[/TD]
[TD="align: center"]2[/TD]
[/TR]
</tbody>[/TABLE]

please advise!
Thanks!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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