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

Hi
Can anyone help me loop through the tabs in a certain position?
I currently use:
for each ws in thisworkbook.worksheets
but the loops all, I only want to loop the tabs named between eg USaa and USzz

Grateful for all help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default loop through tabs

I think you would have to test them

For Each ws In Thisworkbook.Worksheets
If Left(ws.Name,2) = "US" Then
'do your stuff
End If
Next ws

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Newbie" wrote in message
...
Hi
Can anyone help me loop through the tabs in a certain position?
I currently use:
for each ws in thisworkbook.worksheets
but the loops all, I only want to loop the tabs named between eg USaa and

USzz

Grateful for all help.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default loop through tabs

Newbie

If you are looking for something like

For each wks in ThisWorkbook.Worksheets("US*")

it doesn't exist

You could set up an array of the worksheet names and iterate through that
array or, for the speed that Excel will check the sheet tab names just
exclude the code running using and If...Then...End If. That below will
simply move to check the next sheet if the first two characters are not US

For Each wks in ThisWorkbook.Worksheets
If UCase(Left(Wks.Name,2))="US" Then
'Do stuff here
End If
Next wks

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Newbie" wrote in message
...
Hi
Can anyone help me loop through the tabs in a certain position?
I currently use:
for each ws in thisworkbook.worksheets
but the loops all, I only want to loop the tabs named between eg USaa and
USzz

Grateful for all help.


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

Hell Bob, at least I put a UCase in ;-)

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Nick Hodge" wrote in message
...
Newbie

If you are looking for something like

For each wks in ThisWorkbook.Worksheets("US*")

it doesn't exist

You could set up an array of the worksheet names and iterate through that
array or, for the speed that Excel will check the sheet tab names just
exclude the code running using and If...Then...End If. That below will
simply move to check the next sheet if the first two characters are not US

For Each wks in ThisWorkbook.Worksheets
If UCase(Left(Wks.Name,2))="US" Then
'Do stuff here
End If
Next wks

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Newbie" wrote in message
...
Hi
Can anyone help me loop through the tabs in a certain position?
I currently use:
for each ws in thisworkbook.worksheets
but the loops all, I only want to loop the tabs named between eg USaa and
USzz

Grateful for all help.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default loop through tabs

Try something like

Dim N As Long
Dim WS As Worksheet
For N = Worksheets("USaa").Index To Worksheets("USzz").Index
Set WS = Worksheets(N)
''''''''''''''''''''''''''''''''''''''
' Done something with WS
''''''''''''''''''''''''''''''''''''''
Next N


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"Newbie" wrote in message
...
Hi
Can anyone help me loop through the tabs in a certain position?
I currently use:
for each ws in thisworkbook.worksheets
but the loops all, I only want to loop the tabs named between eg USaa and
USzz

Grateful for all help.



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
tabs are missing even though 'tools-options-view-sheet tabs' ok? rgranell Excel Worksheet Functions 3 August 16th 08 04:25 PM
hide tabs from view then lock tabs? slowboat Excel Discussion (Misc queries) 1 December 19th 07 07:06 AM
Run out of resources .... loop to new tabs Doug929 Excel Programming 3 September 16th 05 04:52 PM
Loop to new tabs Doug929 Excel Programming 1 September 15th 05 06:36 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM


All times are GMT +1. The time now is 05:13 AM.

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

About Us

"It's about Microsoft Excel"