Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Worksheet with Wildcard


Hi guys,

I like to know how to find a worksheet in a workbook in which I know
the name begins with the word "Completed". The trouble is I am not too
sure how you incorporate wildcard with the search as well, e.g. the
sheet could be called "Completed 0506"

After the search i would like to set that worksheet to a worksheet
variable as well, so i can acesss that worksheet for further data
access.

Many thanks


--
philwongnz
------------------------------------------------------------------------
philwongnz's Profile: http://www.excelforum.com/member.php...o&userid=26283
View this thread: http://www.excelforum.com/showthread...hreadid=565508

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find Worksheet with Wildcard

dim wks as worksheet
dim CompWks as worksheet

set CompWks = nothing
for each wks in activeworkbook.worksheets
if lcase(wks.name) like "completed *" then
set compwks = wks
exit for
end if
next wks

if compwks is nothing then
'not found
'what should happen
else
'found it!
end if

philwongnz wrote:

Hi guys,

I like to know how to find a worksheet in a workbook in which I know
the name begins with the word "Completed". The trouble is I am not too
sure how you incorporate wildcard with the search as well, e.g. the
sheet could be called "Completed 0506"

After the search i would like to set that worksheet to a worksheet
variable as well, so i can acesss that worksheet for further data
access.

Many thanks

--
philwongnz
------------------------------------------------------------------------
philwongnz's Profile: http://www.excelforum.com/member.php...o&userid=26283
View this thread: http://www.excelforum.com/showthread...hreadid=565508


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Worksheet with Wildcard


Many thanks Dave,

I was lucky enough to came up with a solution just before i rechec
anyone has replied, so I can post the solution to my question. Here'
what I've done, which is almost the same as your solution, except th
helper methods returns a worksheet object rather than a boolean. As
need to do several searches on different workbooks I have used
workbook as a criteria for this function, rather than activiting th
workbook prior to my search.

Public Function SheetExists(currentWorkbook As Workbook, strSearchFo
As String) As Worksheet
Dim tempWks As Worksheet

For Each tempWks In currentWorkbook.Worksheets
If tempWks.Name Like strSearchFor Then
Set SheetExists = tempWks
Exit Function
Else
Set SheetExists = Nothing
End If
Next tempWks
End Functio

--
philwongn
-----------------------------------------------------------------------
philwongnz's Profile: http://www.excelforum.com/member.php...fo&userid=2628
View this thread: http://www.excelforum.com/showthread.php?threadid=56550

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find Worksheet with Wildcard

My suggestion actually used a worksheet variable -- compwks.

You may want to make sure you have:
option compare text
at the top of the module

Or make sure you pass the correct case (or use ucase/lcase) in your function.

philwongnz wrote:

Many thanks Dave,

I was lucky enough to came up with a solution just before i recheck
anyone has replied, so I can post the solution to my question. Here's
what I've done, which is almost the same as your solution, except the
helper methods returns a worksheet object rather than a boolean. As I
need to do several searches on different workbooks I have used a
workbook as a criteria for this function, rather than activiting the
workbook prior to my search.

Public Function SheetExists(currentWorkbook As Workbook, strSearchFor
As String) As Worksheet
Dim tempWks As Worksheet

For Each tempWks In currentWorkbook.Worksheets
If tempWks.Name Like strSearchFor Then
Set SheetExists = tempWks
Exit Function
Else
Set SheetExists = Nothing
End If
Next tempWks
End Function

--
philwongnz
------------------------------------------------------------------------
philwongnz's Profile: http://www.excelforum.com/member.php...o&userid=26283
View this thread: http://www.excelforum.com/showthread...hreadid=565508


--

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
Using wildcard characters in find & replace Tola Excel Worksheet Functions 4 May 5th 10 07:35 PM
Find and Replace Command Using Wildcard Help rgilbreath Excel Discussion (Misc queries) 1 October 10th 08 04:01 AM
Find Replace Wildcard dk New Users to Excel 9 September 23rd 08 03:45 AM
Using IF to find text + wildcard? Outlook, eh? Excel Worksheet Functions 8 July 3rd 07 04:46 PM
Find wildcard text within a cell indiana1138 Excel Programming 6 June 1st 05 12:18 AM


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