Sub totals in a macro

dkuyper

New Member
Joined
Jul 29, 2005
Messages
47
I am trying to run a macro that will select data that matchs certain criteria for a list of names from a selected sheet and then sub-total this data in another sheet. The macro runs fin for most names in the list but comes up with a run time error when a name in the list has not data to sub-total. The error is as follows:

Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(10), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Is there any way to get the macro to ignore names that have no data?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I've had a suggestion from somebody I work with but still require some help. Apparently because the sheets I'm trying to sub-total have 8 rows at the top of each sheet I can set the macro to count the number of rows in the sheet and if this is greater than 8 to run the sub-total if not then it should skip the sub-totaling. Would anybody know how the macro would need to be adjusted? The macro is currently set up as below:

Range("A1").Select
Application.DisplayAlerts = False
Application.EnableEvents = False
Range("A8:J8").Select
Selection.End(xlDown).Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(10), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True

This selects a new sheet pastes in the top 8 rows and the runs the sub-total

Any help would be greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,889
Messages
6,181,606
Members
453,055
Latest member
cope7895

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