Testing for subtotal?

tourless

Board Regular
Joined
Feb 8, 2007
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hi Folks,

I have a routine that takes a bunch of sheets in an array and performs a few actions including removing a subtotal. But what I'm noticing is if the active sheet in the loop does not have a subtotal I get 'RemoveSubtotal method of Range of class failed' error. Is it possible for first test for the existence of a subtotal and remove it only if it does exist? Here's what I'm working with... yeah I know about selecting...

Code:
 'Remove previous results
    For Each ResultsSh In Sheets(Array("HT-LB-W1V", "COG-M-LB-W1V", "COG-CMPS-LB-W1V", "Revenue", "Revenue2"))
        'ResultsSh.Select
        'Clear old result set from array
        ResultsSh.Rows.Hidden = False
        ResultsSh.Columns("A:B").Delete Shift:=xlToLeft
        ResultsSh.Range("A1").RemoveSubtotal
        'ResultsSh.Range("A1").Select
    Next

Thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Replace the RemoveSubtotal line with:

Code:
Range("A1").ListObject.ShowTotals = False
 
Last edited:
Upvote 0
Yes we are, and yes it is.

Ah, did you prefix the line of code with ResultsSh, as in:

Code:
ResultsSh.Range("A1").ListObject.ShowTotals = False

My bad if you didn't. If you did though, I can see no reason why you should get an error...
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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