Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Worksheet Name

Status
Not open for further replies.

laurenbattaglia

Technical User
May 3, 2002
28
US
I have a workbook is a download from the web, that has named sheets in it. The sheet name has been changed on some of the downloads, so I need to be able to find either sheet name. I am trying to do something like the statement below, but I am having trouble with the syntax.


If Sheets.name <> fsBS Then
Sheets(fsBSN).Select
Else
Sheets(fsBS).Select

Any help would be appreciated.
 
If I understand correctly, there are multiple sheets in the workbook, one of which is named either fsBSN or fsBS.

Assuming fsBS and fsBSN are not string variables but actual sheet names, then you can use this:
[blue]
Code:
  For Each wks In ActiveWorkbook.Sheets
    If wks.Name = &quot;fsBS&quot; Or wks.Name = &quot;fsBSN&quot; Then
      wks.Activate
    End If
  Next wks
[/color]

If they are variables, then omit the double-quote marks.
 
It would be much better to be consistent. That said, if you have 2 possible sheet names (fsBS and fsBSN) this will activate the first sheet
Code:
    Dim mySheet As Worksheet
    For Each mySheet In ActiveWorkbook.Worksheets
        If mySheet.Name = &quot;fsBS&quot; Or mySheet.Name = &quot;fsBSN&quot; Then
            mySheet.Activate
            Exit For
        End If
    Next
 
lol Zathras.... great minds and all that stuff [2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top