Macro To Sum Lines With Same Criteria

crashing1912

New Member
Joined
Sep 8, 2011
Messages
19
I need a macro to "subtotal" the data below. Basically, there are invoices that can have different "Types" of costs on them, however, sometimes the information provided by the billing dept. the types can be repeated. For example, invoice 57 for Kansas has P listed twice, as well as T. I need the macro to sum columns Gross, Discount & billed for "P" on to one line.
The criteria would be sum Gross, Discount, & billed when the state, invoice & type are the same.
[TABLE="width: 500"]
<tbody>[TR]
[TD]State[/TD]
[TD]Invoice[/TD]
[TD]Type[/TD]
[TD]Gross[/TD]
[TD]Discount[/TD]
[TD]Billed[/TD]
[/TR]
[TR]
[TD]Michigan[/TD]
[TD]56[/TD]
[TD]T[/TD]
[TD]500[/TD]
[TD]0[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD]Michigan[/TD]
[TD]56[/TD]
[TD]R[/TD]
[TD]100[/TD]
[TD]0[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]Kanas[/TD]
[TD]57[/TD]
[TD]P[/TD]
[TD]100[/TD]
[TD]0[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]Kansas[/TD]
[TD]57[/TD]
[TD]P[/TD]
[TD]300[/TD]
[TD]0[/TD]
[TD]300[/TD]
[/TR]
[TR]
[TD]Kansas[/TD]
[TD]57[/TD]
[TD]T[/TD]
[TD]100[/TD]
[TD]0[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]Texas[/TD]
[TD]58[/TD]
[TD]R[/TD]
[TD]200[/TD]
[TD]0[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD]Texas[/TD]
[TD]58[/TD]
[TD]R[/TD]
[TD]100[/TD]
[TD]0[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]Oklahoma[/TD]
[TD]59[/TD]
[TD]T[/TD]
[TD]200[/TD]
[TD]0[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD]Oklahoma[/TD]
[TD]59[/TD]
[TD]T[/TD]
[TD]300[/TD]
[TD]0[/TD]
[TD]300[/TD]
[/TR]
</tbody>[/TABLE]


The end result should look like this:

[TABLE="width: 500"]
<tbody>[TR]
[TD]State[/TD]
[TD]Invoice[/TD]
[TD]Type[/TD]
[TD]Gross[/TD]
[TD]Discount[/TD]
[TD]Billed[/TD]
[/TR]
[TR]
[TD]Michigan[/TD]
[TD]56[/TD]
[TD]T[/TD]
[TD]500[/TD]
[TD]0[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD]Michigan[/TD]
[TD]56[/TD]
[TD]R[/TD]
[TD]100[/TD]
[TD]0[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]Kansas[/TD]
[TD]57[/TD]
[TD]P[/TD]
[TD]400[/TD]
[TD]0[/TD]
[TD]400[/TD]
[/TR]
[TR]
[TD]Kansas[/TD]
[TD]57[/TD]
[TD]T[/TD]
[TD]100[/TD]
[TD]0[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]Texas[/TD]
[TD]58[/TD]
[TD]R[/TD]
[TD]300[/TD]
[TD]0[/TD]
[TD]300[/TD]
[/TR]
[TR]
[TD]Oklahoma[/TD]
[TD]59[/TD]
[TD]T[/TD]
[TD]500[/TD]
[TD]0[/TD]
[TD]500[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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