Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default worksheet looping with varying labels (aka Need to Find the John!)

Here's the problem:

Suppose a macro creates a certain number of worksheets (which varies
from dataset to dataset). Further suppose that text labels (in the
tabs) are created by the macro for each worksheet (that also vary from
workbook to workbook).

Now, I want the macro to go through the worksheets and pick out the
ones that have particular text.

Example:

Macro creates 6 worksheets for this dataset:

John - 1
John-2
Mary -1
Mary-2
Fred
Debbie

I want to find the John's.

I envision a loop where it finds the first John (John - 1) and then
executes the appropriate actions on this worksheet. It then finds the
second John (John-2) and executes those same actions. I can do this,
but I can't get it to loop through the worksheets and pick these
particular worksheets.

Anyone have any ideas on how to find these John's

Jeff Miller

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default worksheet looping with varying labels (aka Need to Find the John!)

Worksheets are a collection. Use a for each loop to search through the
worksheets in the workbook. Use an if statement if you find what you are
looking for then perform the action necessary.


"alphapoint05" wrote:

Here's the problem:

Suppose a macro creates a certain number of worksheets (which varies
from dataset to dataset). Further suppose that text labels (in the
tabs) are created by the macro for each worksheet (that also vary from
workbook to workbook).

Now, I want the macro to go through the worksheets and pick out the
ones that have particular text.

Example:

Macro creates 6 worksheets for this dataset:

John - 1
John-2
Mary -1
Mary-2
Fred
Debbie

I want to find the John's.

I envision a loop where it finds the first John (John - 1) and then
executes the appropriate actions on this worksheet. It then finds the
second John (John-2) and executes those same actions. I can do this,
but I can't get it to loop through the worksheets and pick these
particular worksheets.

Anyone have any ideas on how to find these John's

Jeff Miller


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default worksheet looping with varying labels (aka Need to Find the John!)

Hi Jeff

you can loop through the worksheets collection like this:

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If Left(UCase(ws.Name), 4) = "JOHN" Then
'do sheet stuff
End If
Next ws


Hope this helps
Rowan

alphapoint05 wrote:
Here's the problem:

Suppose a macro creates a certain number of worksheets (which varies
from dataset to dataset). Further suppose that text labels (in the
tabs) are created by the macro for each worksheet (that also vary from
workbook to workbook).

Now, I want the macro to go through the worksheets and pick out the
ones that have particular text.

Example:

Macro creates 6 worksheets for this dataset:

John - 1
John-2
Mary -1
Mary-2
Fred
Debbie

I want to find the John's.

I envision a loop where it finds the first John (John - 1) and then
executes the appropriate actions on this worksheet. It then finds the
second John (John-2) and executes those same actions. I can do this,
but I can't get it to loop through the worksheets and pick these
particular worksheets.

Anyone have any ideas on how to find these John's

Jeff Miller

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default worksheet looping with varying labels (aka Need to Find the John!)

What if I'm not looking for the entire text of the tab but just one
word within it

Jeff

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default worksheet looping with varying labels (aka Need to Find the John!)

Thank you very much! This worked well. I had to make one change....had
to remove UCase due to the nature of my names.

Thanks again,
Jeff



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default worksheet looping with varying labels (aka Need to Find the John!)

Glad it helped. The UCASE is there (matched with a search for "JOHN") so
that it does not matter how the names are entered. If you only want to
change sheets where the name is entered with a specific case then remove
the UCASE.

Regards
Rowan

alphapoint05 wrote:
Thank you very much! This worked well. I had to make one change....had
to remove UCase due to the nature of my names.

Thanks again,
Jeff

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
Lookup columns (varying qty), then find MIN NRath Excel Worksheet Functions 6 February 8th 10 09:58 PM
Changing text case in entire database column from JOHN to John Kimberly in Palm Springs Excel Discussion (Misc queries) 2 October 10th 06 06:26 PM
How to find and replace blank space (x) in John Smithx in Excel? JoeSAT Excel Discussion (Misc queries) 5 March 19th 06 04:39 PM
how to format Doe,John to Doe, John (space after a comma) asuncionw Excel Worksheet Functions 8 November 4th 05 01:56 PM
Looping Through Chart Labels Dan Gesshel Excel Programming 2 August 3rd 03 02:59 AM


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