Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Using wildcard characters in find & replace | Excel Worksheet Functions | |||
Find and Replace Command Using Wildcard Help | Excel Discussion (Misc queries) | |||
Find Replace Wildcard | New Users to Excel | |||
Using IF to find text + wildcard? | Excel Worksheet Functions | |||
Find wildcard text within a cell | Excel Programming |