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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Name of sheets

Status
Not open for further replies.

Gianricus

Programmer
Apr 2, 2003
62
IT
Hi,
i have one excel-file and i have more sheet.
I have one sheet named "DS".
It's possible know if the sheet named "DS" exist in my workbook?

Thanks
 
This code will do what you want:


Sub FindSheet()
Dim SheetFound As Boolean

SheetFound = False

For Each Sheet In Sheets
If Sheet.Name = "DS" Then
MsgBox "Found Sheet DS"
SheetFound = True
End If
Next

If SheetFound = False Then
MsgBox "Sheet DS not found."
End If
End Sub

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Ok, thanks, it's one solution, but it is not possible know immediately(with a propriety) if one name of sheets is present??

Thanks.

Bye
 
To know more immediate, you would have try renaming another sheet to the same name in the wb. But it may be easier with jebenson's code, as it is not restricted to any particular workbook.
 
Here's another clean & simple way that works for me.

if(iserror(DS!A1),"Doesn't exist","Exists")

Any cell will work. I used A1 in this example.
 
your workbook (say MyBook) has a collection .Sheets
loop through the collection and test for name
I can't remember the code exactly but:

function isfound as boolean
isfound = false
for ic = 0 to mybook.sheets.count
if mybook.sheets(ic).name = "DS" the isfound = true
next ic
exit function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top