View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Search for worksheet in workbook


Liz, try the below

On Error Resume Next
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")

If sh Is Nothing Then
MsgBox ("The ""My Template"" tab cannot be found in this workbook.")
Else
sh.Activate
End If

If this post helps click Yes
---------------
Jacob Skaria


"Liz" wrote:

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