PC Review


Reply
Thread Tools Rate Thread

apply Macro to all sheets in workbook - loop

 
 
transferxxx@gmail.com
Guest
Posts: n/a
 
      19th Jul 2007
Can anybody modify my macro below works on all worksheets in my
workbook (loop) - instead of applying the macro to individual sheets

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 Sub

Thxs

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      19th Jul 2007
Sub Statement()

For Each ws In Worksheets
ws.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

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

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

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

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

Next ws
End Sub


"(E-Mail Removed)" wrote:

> Can anybody modify my macro below works on all worksheets in my
> workbook (loop) - instead of applying the macro to individual sheets
>
> 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 Sub
>
> Thxs
>
>

 
Reply With Quote
 
transferxxx@gmail.com
Guest
Posts: n/a
 
      19th Jul 2007
On Jul 19, 10:36 am, Joel <J...@discussions.microsoft.com> wrote:
> Sub Statement()
>
> For Each ws In Worksheets
> ws.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
>
> ws.Range("A1").CurrentRegion.Subtotal _
> GroupBy:=6, Function:=xlSum, _
> TotalList:=Array(7), _
> Replace:=True, _
> PageBreaks:=False, _
> SummaryBelowData:=True
>
> ws.Range("A1").CurrentRegion.Replace _
> What:="SUBTOTAL(9,", _
> Replacement:="sum(", _
> LookAt:=xlPart, _
> SearchOrder:=xlByRows, _
> MatchCase:=False, _
> SearchFormat:=False, _
> ReplaceFormat:=False
>
> ws.Range("A1").CurrentRegion.AutoFormat _
> Format:=xlRangeAutoFormatSimple, _
> Number:=True, _
> Font:=False, _
> Alignment:=False, _
> Border:=True, _
> Pattern:=True, _
> Width:=False
>
> ws.Columns("G:G").Select
> Selection.Replace _
> What:="SUBTOTAL(9,", _
> Replacement:="SUM(", _
> LookAt:=xlPart, _
> SearchOrder:=xlByRows, _
> MatchCase:=False, _
> SearchFormat:=False, _
> ReplaceFormat:=False
>
> Next ws
> End Sub
>
> "transfer...@gmail.com" wrote:
> > Can anybody modify my macro below works on all worksheets in my
> > workbook (loop) - instead of applying the macro to individual sheets

>
> > 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 Sub

>
> > Thxs


thxs a lot!!!

 
Reply With Quote
 
transferxxx@gmail.com
Guest
Posts: n/a
 
      19th Jul 2007
On Jul 19, 10:36 am, Joel <J...@discussions.microsoft.com> wrote:
> Sub Statement()
>
> For Each ws In Worksheets
> ws.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
>
> ws.Range("A1").CurrentRegion.Subtotal _
> GroupBy:=6, Function:=xlSum, _
> TotalList:=Array(7), _
> Replace:=True, _
> PageBreaks:=False, _
> SummaryBelowData:=True
>
> ws.Range("A1").CurrentRegion.Replace _
> What:="SUBTOTAL(9,", _
> Replacement:="sum(", _
> LookAt:=xlPart, _
> SearchOrder:=xlByRows, _
> MatchCase:=False, _
> SearchFormat:=False, _
> ReplaceFormat:=False
>
> ws.Range("A1").CurrentRegion.AutoFormat _
> Format:=xlRangeAutoFormatSimple, _
> Number:=True, _
> Font:=False, _
> Alignment:=False, _
> Border:=True, _
> Pattern:=True, _
> Width:=False
>
> ws.Columns("G:G").Select
> Selection.Replace _
> What:="SUBTOTAL(9,", _
> Replacement:="SUM(", _
> LookAt:=xlPart, _
> SearchOrder:=xlByRows, _
> MatchCase:=False, _
> SearchFormat:=False, _
> ReplaceFormat:=False
>
> Next ws
> End Sub
>
> "transfer...@gmail.com" wrote:
> > Can anybody modify my macro below works on all worksheets in my
> > workbook (loop) - instead of applying the macro to individual sheets

>
> > 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 Sub

>
> > Thxs


Too good to be true - It does not work - could you pls retry or
someone else help - thxs


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apply Conditional Format to all sheets in same workbook Der Musensohn Microsoft Excel Misc 4 26th Feb 2010 04:24 PM
Apply same filter to all sheets in a workbook manfareed Microsoft Excel Programming 9 31st Jul 2008 03:34 PM
How do I get this Macro to apply to ALL sheets in workbook? =?Utf-8?B?TmV3c2dhbA==?= Microsoft Excel Programming 2 2nd Aug 2007 09:43 PM
how to apply the same header or footer to all sheets in workbook =?Utf-8?B?THVlbmRhIEJ1cmtl?= Microsoft Excel Worksheet Functions 1 1st Nov 2006 05:45 PM
apply same custom header to all sheets in a workbook jchoy Microsoft Excel Misc 2 20th Aug 2004 01:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 PM.