Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default Macro To Remove Subtotals from ALL Worksheets

Hi guys!

I'm running into a bit of a snag here. I have several workbooks that
contain 20+ worksheets each. I am having a major problem writing a
macro to remove the subtotals from all the worksheets in the work
book. Posted below is a couple macros I have tried. The funny thing
is, that it will remove the subtotals for one sheet only. Yet, if I
use this same looping macro with a different function, such as put
text in A1 on all worksheets, it works like a champ... I don't need
anything fancy, I just need a simple way to remove all subtotals from
all worksheets within the book. Thanks.

Public Sub DoToAll()

'Declare our variable
Dim ws As Worksheet
For Each ws In Worksheets
'place code between the For and Next
'for what you would like to do to
'each sheet
Cells.Select
Selection.RemoveSubtotal
Next
End Sub


I have also tried: This one shows is from Microsoft's website, with
the addition of my remove subtotal section. It does show and have you
click each worksheet name in a pop-up box showing its working, with no
prevail...

Sub WorksheetLoop()

Dim WS_Count As Integer
Dim I As Integer

' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = ActiveWorkbook.Worksheets.Count

' Begin the loop.
For I = 1 To WS_Count
Cells.Select
Selection.RemoveSubtotal
' Insert your code here.
' The following line shows how to reference a sheet within
' the loop by displaying the worksheet name in a dialog box.
MsgBox ActiveWorkbook.Worksheets(I).Name

Next I

End Sub



And:

Sub Loop
For Each ws In Worksheets
Cells.Select
Selection.RemoveSubtotal

'Update or do something here

Next
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Macro To Remove Subtotals from ALL Worksheets

Sub WorksheetLoop()

Dim WS_Count As Long
Dim I As Long

' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = ActiveWorkbook.Worksheets.Count

' Begin the loop.
For I = 1 To WS_Count
ActiveWorkbook.Worksheets(I).Cells.RemoveSubtotal
Next I

End Sub

or

Sub Loop
dim ws as worksheet
For Each ws In Worksheets
ws.cells.removeSubtotal
Next ws
End Sub

or if you really wanted to select the cells.
Sub Loop
dim ws as worksheet
For Each ws In Worksheets
ws.select
ws.Cells.Select
Selection.RemoveSubtotal
Next ws
End Sub

vidguru wrote:

Hi guys!

I'm running into a bit of a snag here. I have several workbooks that
contain 20+ worksheets each. I am having a major problem writing a
macro to remove the subtotals from all the worksheets in the work
book. Posted below is a couple macros I have tried. The funny thing
is, that it will remove the subtotals for one sheet only. Yet, if I
use this same looping macro with a different function, such as put
text in A1 on all worksheets, it works like a champ... I don't need
anything fancy, I just need a simple way to remove all subtotals from
all worksheets within the book. Thanks.

Public Sub DoToAll()

'Declare our variable
Dim ws As Worksheet
For Each ws In Worksheets
'place code between the For and Next
'for what you would like to do to
'each sheet
Cells.Select
Selection.RemoveSubtotal
Next
End Sub

I have also tried: This one shows is from Microsoft's website, with
the addition of my remove subtotal section. It does show and have you
click each worksheet name in a pop-up box showing its working, with no
prevail...

Sub WorksheetLoop()

Dim WS_Count As Integer
Dim I As Integer

' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = ActiveWorkbook.Worksheets.Count

' Begin the loop.
For I = 1 To WS_Count
Cells.Select
Selection.RemoveSubtotal
' Insert your code here.
' The following line shows how to reference a sheet within
' the loop by displaying the worksheet name in a dialog box.
MsgBox ActiveWorkbook.Worksheets(I).Name

Next I

End Sub

And:

Sub Loop
For Each ws In Worksheets
Cells.Select
Selection.RemoveSubtotal

'Update or do something here

Next
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default Macro To Remove Subtotals from ALL Worksheets

Thank you SOOOO much!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro To Remove Subtotals from ALL Worksheets vidguru Excel Discussion (Misc queries) 3 May 6th 08 03:30 PM
adding subtotals from several worksheets bernieb Excel Worksheet Functions 2 January 7th 08 09:52 AM
How to remove Subtotals nander Excel Discussion (Misc queries) 1 February 21st 06 05:55 PM
add option in pivot tables to remove subtotals for fields epsoanalyst Excel Worksheet Functions 1 February 16th 06 09:26 PM
Remove the word 'total' from subtotals yahoo Excel Discussion (Misc queries) 2 February 13th 05 01:26 AM


All times are GMT +1. The time now is 04:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"