select range to subtotal?

qwertyjjj

New Member
Joined
Dec 17, 2007
Messages
14
I get data in this format:

Code:
Company 3			
Type	Number	Date	Month	Amount
Inv	13533	09/09/2011	September	251.88
Inv	13545	14/09/2011	September	115.12
Crd	CR13545	19/09/2011	September	-12.00
Inv	13549	16/09/2011	September	103.12
Inv	13556	19/09/2011	September	95.98
Inv	13560	21/09/2011	September	261.00
Inv	13582	03/10/2011	October	34.20
Inv	13589	06/10/2011	October	103.18
Inv	13615	17/10/2011	October	437.03
Inv	13631	25/10/2011	October	314.15
Company 2			
Type	Number	Date	Month	Amount
Inv	13664	04/11/2011	November	347.90

I need to perform subtotals on each company and am trying to do this in code.
How can I cyclce through each company selecting the range?
My current code is

Code:
Sub CalculateTotals()

Dim x As Integer, rownum As Integer, subcount As Integer

      NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
      Range("A1").Select
      For x = 1 To 1000
        
        If ActiveCell.Text <> "Inv" And ActiveCell.Text <> "Crd" And ActiveCell.Text <> "" And ActiveCell.Text <> "Type" Then 'ie it's a company name
            'now select the range to do subtotals on
            ActiveCell.Offset(1, 0).Select 'move down 1 to the header row
            'now cycle through cells to see how many rows of invoices this company has
            subcount = 0
            ActiveCell.Offset(1, 0).Select 'move down 1 row
            'now cycle through to get count
            If ActiveCell.Text = "Inv" Or ActiveCell.Text = "Crd" Then
                subcount = subcount + 1
            
            
            
            
    Range("A2:E12").Select
    Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(5), _
        Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    Columns("D:D").EntireColumn.AutoFit
    
End Sub
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,322
Members
414,053
Latest member
Dual Showman

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
Top