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

I have a workbook with 98 worksheets, What I need is a routine which will
cycle through 98 worksheets and when done leave me where I started (which is
not necessarily the first worksheet)


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

Origanally I was using:

Private Sub Worksheet_Calculate()
Me.Range("E28").Value = Me.Range("G28")
End Sub

But there apparently got to be so many calculations that it would take the
code for ever to finish running, so I swithche to

Private Sub Worksheet_Activate()
Me.Range("E28").Value = Me.Range("G28")
End Sub

To achieve the samething. If someone can point me to better way I would be
very appricative.


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


Hello Patrick,

Add a VBA module to your project and copy this code into it. You can
run the macro by selecting it the macro list (Alt + F8).


Code:
--------------------

Public Sub UpdateWorksheets()

Dim Wks

For Each Wks In Worksheets
Wks.Range("E28") = Wks.Range("G28")
Next Wks

End Sub

--------------------


Happy Holidays,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=495959

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Cycle through all worksheets

maybe something like this

Option Explicit
Sub doAll()

Dim wks As String
Dim sh As Worksheet
wks = ActiveSheet.Name
For Each sh In ThisWorkbook.Sheets
sh.Activate
'do something
Next
Worksheets(wks).Activate
End Sub

--


Gary


"Patrick Simonds" wrote in message
...
Origanally I was using:

Private Sub Worksheet_Calculate()
Me.Range("E28").Value = Me.Range("G28")
End Sub

But there apparently got to be so many calculations that it would take the
code for ever to finish running, so I swithche to

Private Sub Worksheet_Activate()
Me.Range("E28").Value = Me.Range("G28")
End Sub

To achieve the samething. If someone can point me to better way I would be
very appricative.




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


Patrick,

In a general module,


Sub CycleThroWkshts()
Dim sht as Worksheet

Set acSheet=ActiveSheet

For each sht in WorkSheets
sht.Activate
Range("E28").Value = Range("G28")
Next

acSheet.activate

End sub


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=495959



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cycle through all worksheets


Don,

There is need to activate if the respective sheets are not referenced
It's all a matter of style to use

For each sht in Worksheets
sht.Range("E28").Value = sht.Range("G28")
Next

or


For each sht in Worksheets
sht.activate
Range("E28").Value = Range("G28")
Next

Davi

--
david
-----------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...fo&userid=2064
View this thread: http://www.excelforum.com/showthread.php?threadid=49595

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Cycle through all worksheets

Except that activating sheets means that you may want to keep track of where you
started--to go back when you're done.

And if that code is behind a worksheet, then those unqualified ranges will still
refer to the sheet that owns the code--not the activesheet. (Yes, I saw your
warning about putting the code in a general module.)

(I think it's more than a matter of style--but I don't have a better word for it
<vbg.)

davidm wrote:

Don,

There is need to activate if the respective sheets are not referenced.
It's all a matter of style to use

For each sht in Worksheets
sht.Range("E28").Value = sht.Range("G28")
Next

or

For each sht in Worksheets
sht.activate
Range("E28").Value = Range("G28")
Next

David

--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=495959


--

Dave Peterson
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
Shortcut key to cycle through worksheets in the same workbook J K Excel Discussion (Misc queries) 6 April 9th 07 07:12 PM
How do I keep result from 1 iteration cycle to use in next cycle? sgl8akm Excel Discussion (Misc queries) 0 July 27th 06 08:28 PM
How do I cycle through all of the worksheets DMB Excel Discussion (Misc queries) 1 January 9th 06 12:21 AM
How do I cycle through all of the open worksheets? DMB Excel Discussion (Misc queries) 0 January 8th 06 11:24 PM
Cycle thru worksheets in a workbook June Excel Programming 1 July 22nd 04 03:06 PM


All times are GMT +1. The time now is 10:59 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"