ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop worksheets workbook (https://www.excelbanter.com/excel-programming/393743-loop-worksheets-workbook.html)

[email protected]

Loop worksheets workbook
 
Pls help me make the macro below works in all worksheets in one good
i.e loop in all sheets of workbook.

thxs



Sub Statement()


Range("A1").CurrentRegion.Sort Key1:=Range("F2"), Order1:=xlAscending,
Key2:=Range("D2") _
, Order2:=xlAscending, header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal

Range("A1").CurrentRegion.Subtotal GroupBy:=6, Function:=xlSum,
TotalList:=Array(7), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True

Range("A1").CurrentRegion.Replace What:="SUBTOTAL(9,",
Replacement:="sum(", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False

Range("A1").CurrentRegion.AutoFormat Format:=xlRangeAutoFormatSimple,
Number:=True, Font _
:=False, Alignment:=False, Border:=True, Pattern:=True,
Width:=False

Columns("G:G").Select
Selection.Replace What:="SUBTOTAL(9,", Replacement:="SUM(",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False



End Subl


PCLIVE

Loop worksheets workbook
 
One way:

For i = 1 To Worksheets.Count
Sheets(i).Activate

'<YourCode

Next i


HTH,
Paul


wrote in message
oups.com...
Pls help me make the macro below works in all worksheets in one good
i.e loop in all sheets of workbook.

thxs



Sub Statement()


Range("A1").CurrentRegion.Sort Key1:=Range("F2"), Order1:=xlAscending,
Key2:=Range("D2") _
, Order2:=xlAscending, header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal

Range("A1").CurrentRegion.Subtotal GroupBy:=6, Function:=xlSum,
TotalList:=Array(7), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True

Range("A1").CurrentRegion.Replace What:="SUBTOTAL(9,",
Replacement:="sum(", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False

Range("A1").CurrentRegion.AutoFormat Format:=xlRangeAutoFormatSimple,
Number:=True, Font _
:=False, Alignment:=False, Border:=True, Pattern:=True,
Width:=False

Columns("G:G").Select
Selection.Replace What:="SUBTOTAL(9,", Replacement:="SUM(",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False



End Subl





All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com