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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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