Thread: Like operator
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_14_] Bob Phillips[_14_] is offline
external usenet poster
 
Posts: 216
Default Like operator

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stclname As String
Dim stermes As String
Dim sh As Worksheet

Enterclname:

stclname = InputBox("Enter the Client Name")
For Each sh In ThisWorkbook.Worksheets
If stclname Like "*" & sh.Name & "*" Then
sh.Activate
GoTo Exit_Workbook_Open
End If
Next sh

ErrorHandler:

stermes = MsgBox("Check the spelling")
Resume Enterclname

Exit_Workbook_Open:

End Sub

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"marianne" wrote in message
...
I am trying to write vba code so a user can enter a worksheet name using

an
inputbox. The worksheets are named by the client name. e.g. "Smith, Adam"

and
I would like the user to be able to put in the name "Smith" and have the
correct worksheet selected, or a range of worksheets if there are more

than 1
"Smith". How can I write this. The code I have written so far is:

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stclname As String
Dim stermes As String

Enterclname:

stclname = InputBox("Enter the Client Name")
Worksheets(stclname).Activate

Exit_Workbook_Open:
Exit Sub

ErrorHandler:

stermes = MsgBox("Check the spelling")
Resume Enterclname


End Sub

Thanks in advance