View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Search for worksheet in workbook


Forgot to error trap

Sub gotosheet()
Dim mysheet As Worksheet
On Error GoTo nono
Set mysheet = Sheets("Iwannagothere")
If Not mysheet Is Nothing Then mysheet.Select
nono:
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
Sub gotosheet()
Dim mysheet As Worksheet
Set mysheet = Sheets("sheet6")
If Not mysheet Is Nothing Then mysheet.Select
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Liz" wrote in message
...
I am trying to search a workbook for a specific tab name, and activate
that
tab. If that tab does not exist, I would like to exit the sub. I have
the
following code, but it does not find the tab when it exists....can u
help?

Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If sh.Visible = xlSheetVisible Then
If sh.Name = "My Template" Then
sh.Select
Worksheets("My Template").Activate
Exit For
End If
MsgBox ("The ""My Template"" tab cannot be found in this workbook.")
Exit Sub
End If
Next