Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Leo Leo is offline
external usenet poster
 
Posts: 3
Default Code to Loop thru a Workbook

We have a macro in which we want to loop through the
worksheets but don't know the number of worksheets. We
want to loop through and activate a worksheet if it meets
certain criteria, but don't know the code to do this. Are
we on the right track below? Can someone fill in the two
missing pieces of code in the parens below?


Sub WorksheetLoop ()

Dim WsCount as Double

WsCount = (How do we get this?)

For I = 1 to WsCount
If (How do we identify the worksheet name here in
VB?) = "AA" then
VB lines of code here
End If
Next I

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Code to Loop thru a Workbook

Leo

one way:

Sub test()
For Each ws In Worksheets
Debug.Print ws.Name
Next 'ws
End Sub

Regards

Trevor


"Leo" wrote in message
...
We have a macro in which we want to loop through the
worksheets but don't know the number of worksheets. We
want to loop through and activate a worksheet if it meets
certain criteria, but don't know the code to do this. Are
we on the right track below? Can someone fill in the two
missing pieces of code in the parens below?


Sub WorksheetLoop ()

Dim WsCount as Double

WsCount = (How do we get this?)

For I = 1 to WsCount
If (How do we identify the worksheet name here in
VB?) = "AA" then
VB lines of code here
End If
Next I

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Code to Loop thru a Workbook

Hi Leo

Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If sh.Name = "ddd" Then
'..................
End If
Next sh


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Leo" wrote in message ...
We have a macro in which we want to loop through the
worksheets but don't know the number of worksheets. We
want to loop through and activate a worksheet if it meets
certain criteria, but don't know the code to do this. Are
we on the right track below? Can someone fill in the two
missing pieces of code in the parens below?


Sub WorksheetLoop ()

Dim WsCount as Double

WsCount = (How do we get this?)

For I = 1 to WsCount
If (How do we identify the worksheet name here in
VB?) = "AA" then
VB lines of code here
End If
Next I

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Code to Loop thru a Workbook

WsCount = Worksheets.Count

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Leo" wrote in message
...
We have a macro in which we want to loop through the
worksheets but don't know the number of worksheets. We
want to loop through and activate a worksheet if it meets
certain criteria, but don't know the code to do this. Are
we on the right track below? Can someone fill in the two
missing pieces of code in the parens below?


Sub WorksheetLoop ()

Dim WsCount as Double

WsCount = (How do we get this?)

For I = 1 to WsCount
If (How do we identify the worksheet name here in
VB?) = "AA" then
VB lines of code here
End If
Next I

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
Loop or Find code ?? need help !! EBnLP01 Excel Worksheet Functions 4 October 29th 09 05:47 PM
Loop for VBA code? paulinoluciano Excel Worksheet Functions 5 December 28th 05 01:30 PM
How to Loop some code Phil Osman Excel Discussion (Misc queries) 2 August 19th 05 11:14 AM
VBE code in a loop loloflores Excel Programming 0 April 30th 04 12:28 PM
Creating a loop from my code Todd Huttenstine\(Remote\) Excel Programming 3 November 28th 03 04:05 PM


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