Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default loop through all worksheets

My workbook has over 100 worksheets. I want to be able to execute the code
below, have it cycle through all worksheets and when done leave the
worksheet that was active when the code was started active.

Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
With Sheets(n)
.Activate
.Range("A3").Activate
End With
Next n
Application.ScreenUpdating = True

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default loop through all worksheets

Sub LoopAllWS()
Dim ws As Worksheet
Dim wsStart As Worksheet

Set wsStart = ActiveSheet
For Each ws In Worksheet
With ws
'No need to use Select use .With code here
End With
Next ws
wsStart.Activate
End Sub




--
Regards
Dave Hawley
www.ozgrid.com
"ordnance1" wrote in message
...
My workbook has over 100 worksheets. I want to be able to execute the code
below, have it cycle through all worksheets and when done leave the
worksheet that was active when the code was started active.

Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
With Sheets(n)
.Activate
.Range("A3").Activate
End With
Next n
Application.ScreenUpdating = True


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default loop through all worksheets

Thanks, but I get an Object Required error and the following line of text is
highlighted:

For Each ws In Worksheet



"ozgrid.com" wrote in message
...
Sub LoopAllWS()
Dim ws As Worksheet
Dim wsStart As Worksheet

Set wsStart = ActiveSheet
For Each ws In Worksheet
With ws
'No need to use Select use .With code here
End With
Next ws
wsStart.Activate
End Sub




--
Regards
Dave Hawley
www.ozgrid.com
"ordnance1" wrote in message
...
My workbook has over 100 worksheets. I want to be able to execute the
code below, have it cycle through all worksheets and when done leave the
worksheet that was active when the code was started active.

Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
With Sheets(n)
.Activate
.Range("A3").Activate
End With
Next n
Application.ScreenUpdating = True


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default loop through all worksheets

There is a typo in the statement, use this:

For Each ws In Worksheets

Regards,
Per

"ordnance1" skrev i meddelelsen
...
Thanks, but I get an Object Required error and the following line of text
is highlighted:

For Each ws In Worksheet



"ozgrid.com" wrote in message
...
Sub LoopAllWS()
Dim ws As Worksheet
Dim wsStart As Worksheet

Set wsStart = ActiveSheet
For Each ws In Worksheet
With ws
'No need to use Select use .With code here
End With
Next ws
wsStart.Activate
End Sub




--
Regards
Dave Hawley
www.ozgrid.com
"ordnance1" wrote in message
...
My workbook has over 100 worksheets. I want to be able to execute the
code below, have it cycle through all worksheets and when done leave the
worksheet that was active when the code was started active.

Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
With Sheets(n)
.Activate
.Range("A3").Activate
End With
Next n
Application.ScreenUpdating = True


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default loop through all worksheets

Thanks

"Per Jessen" wrote in message
...
There is a typo in the statement, use this:

For Each ws In Worksheets

Regards,
Per

"ordnance1" skrev i meddelelsen
...
Thanks, but I get an Object Required error and the following line of text
is highlighted:

For Each ws In Worksheet



"ozgrid.com" wrote in message
...
Sub LoopAllWS()
Dim ws As Worksheet
Dim wsStart As Worksheet

Set wsStart = ActiveSheet
For Each ws In Worksheet
With ws
'No need to use Select use .With code here
End With
Next ws
wsStart.Activate
End Sub




--
Regards
Dave Hawley
www.ozgrid.com
"ordnance1" wrote in message
...
My workbook has over 100 worksheets. I want to be able to execute the
code below, have it cycle through all worksheets and when done leave
the worksheet that was active when the code was started active.

Application.ScreenUpdating = False
Dim n As Single
For n = 1 To Sheets.Count
With Sheets(n)
.Activate
.Range("A3").Activate
End With
Next n
Application.ScreenUpdating = True



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default loop through all worksheets

On May 19, 10:27*am, "ordnance1" wrote:
My workbook has over 100 worksheets. I want to be able to execute the code
below, have it cycle through all worksheets and when done leave the
worksheet that was active when the code was started active.

Application.ScreenUpdating = False
Dim n As Single
* * For n = 1 To Sheets.Count
* * * * With Sheets(n)
* * * * * * .Activate
* * * * * * .Range("A3").Activate
* * * * End With
* * Next n
Application.ScreenUpdating = True


Probably you want to activate the first cell of each sheet so that
user get it right A1 on reaching sheets


You can use following code for speed

Sub YourSubName()
Dim ws As Worksheet
Dim wsStart As Worksheet

Set wsStart = ActiveSheet
For Each ws In Worksheet
If ws.Visible = xlSheetVisible Then
Application.GoTo ws.Range("a1"), True
End If
Next ws
wsStart.Activate
End Sub


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
Worksheets in Loop ReportSmith Excel Programming 1 June 11th 09 04:19 PM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 0 March 27th 07 11:17 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Loop Through worksheets Stephen[_9_] Excel Programming 5 April 20th 04 01:46 PM


All times are GMT +1. The time now is 09:17 AM.

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

About Us

"It's about Microsoft Excel"