Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default select sheets by name - how?

Following problem:
There are some workbooks with 12 sheets each. these sheets are called:
"Jan 00", "Feb 00", ...,"Dec 00" or "Jan 03, ..., "Dec 03".

I know that I can refer to the 'internal' number of the sheets (1 to
12). But in my case I have to select the sheets by the
user-defined-name. The macro should exist over many years, so I can
only use part of the name = monthname.

I would like to have code like that:

If Sheets(Worksheets(x).Name).Name = "July 00" Then '(that works)

where the 00-part is variable!

Is there a possibility to refer only to a PART of the user defined
sheet name?

TIA Walt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default select sheets by name - how?

You can use the Left function to get the first 3 letters,
for example:

If Left(Sheets(Worksheets(x).Name).Name,3) = "Jul" Then

Hope this helps,
Helen


-----Original Message-----
Following problem:
There are some workbooks with 12 sheets each. these

sheets are called:
"Jan 00", "Feb 00", ...,"Dec 00" or "Jan 03, ..., "Dec

03".

I know that I can refer to the 'internal' number of the

sheets (1 to
12). But in my case I have to select the sheets by the
user-defined-name. The macro should exist over many

years, so I can
only use part of the name = monthname.

I would like to have code like that:

If Sheets(Worksheets(x).Name).Name = "July 00"

Then '(that works)

where the 00-part is variable!

Is there a possibility to refer only to a PART of the

user defined
sheet name?

TIA Walt
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default select sheets by name - how?

You can write a function like this:

Function SheetByName(ByVal NamePattern As String) As
Worksheet
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
If UCase(sh.Name) Like UCase(NamePattern) Then
Set SheetByName = sh
Exit For
End If
Next sh
End Function

and then use it:

Public Sub Test()
Dim MyWorkSheet As Worksheet
Dim Pattern As String
Pattern = "feb*"
Set MyWorkSheet = SheetByName(Pattern)
If MyWorkSheet Is Nothing Then
MsgBox "No sheets matching '" & Pattern & "' found",
vbCritical
Else
MyWorkSheet.Activate
' some other code goes here
Set MyWorkSheet = Nothing
End If
End Sub

-----Original Message-----


Is there a possibility to refer only to a PART of the

user defined
sheet name?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default select sheets by name - how?

Walt,

This is untested, but might work.

Just add a way to input mywsh (InputBox, ComboBox, ListBox, Drop Down, etc.)

Dim x as Integer, wsh as Integer, mywsh as String

mywsh = "July 05"
For x = 1 to ActiveWorkbook.Worksheets.Count
If Lcase(Sheets(x).Name) = Lcase(Left(mywsh,3)) then
Sheets(x).Select
Exit For
End If
Next

You could also use a Do .... While .... Loop

steve

"Walt" wrote in message
om...
Following problem:
There are some workbooks with 12 sheets each. these sheets are called:
"Jan 00", "Feb 00", ...,"Dec 00" or "Jan 03, ..., "Dec 03".

I know that I can refer to the 'internal' number of the sheets (1 to
12). But in my case I have to select the sheets by the
user-defined-name. The macro should exist over many years, so I can
only use part of the name = monthname.

I would like to have code like that:

If Sheets(Worksheets(x).Name).Name = "July 00" Then '(that works)

where the 00-part is variable!

Is there a possibility to refer only to a PART of the user defined
sheet name?

TIA Walt





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default select sheets by name - how?

THX!!!

Walt


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
Macro to select all sheets belvy123 Excel Discussion (Misc queries) 7 March 27th 08 09:43 PM
macro to select all sheets belvy123 Excel Discussion (Misc queries) 1 March 26th 08 04:23 PM
how can i select all sheets in excell? Iraj Excel Worksheet Functions 2 April 25th 07 02:30 PM
USE KEYBOARD TO SELECT ALL SHEETS enos newt gribble Excel Worksheet Functions 4 August 22nd 06 08:50 PM
select sheets for printing bennyob Excel Discussion (Misc queries) 1 November 20th 05 02:52 PM


All times are GMT +1. The time now is 07:11 PM.

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"