.RemoveSubtotal problem

pbt

Well-known Member
Joined
Oct 18, 2005
Messages
1,613
I have this at the very beginning of my code:

Code:
With ws2.UsedRange
    .RemoveSubtotal
    .Cells.Clear

I am doing this to remove subtotals and clear the sheet before the rest of the code runs which will populate the sheet and create Subtotals.

The problem is, when the code is run the first time, the sheet is blank. But this code may be run a number of times after additional input is entered.

If the sheet has info and Subtotals, it works fine, it's just on the first run that it errors out. (understandable, no data)

I know I need an error trap, but don't know how to apply it. Looked at about 50 posts on Search , can't find anything related.

Thanks
Harry
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Joined
Jul 30, 2006
Messages
3,656
Harry,

Depending on what you want to do because of the error, you could try the following addition to your code - it should not error out.

Code:
On Error Resume Next
With ws2.UsedRange 
    .RemoveSubtotal 
    .Cells.Clear

Have a great day,
Stan
 

pbt

Well-known Member
Joined
Oct 18, 2005
Messages
1,613
Thanks Stan

That was to easy. I guess it has been a long week.

Harry
 

Forum statistics

Threads
1,181,607
Messages
5,930,881
Members
436,764
Latest member
avalladarez

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