verify if spesific sheet exist

M

Miri

hi,
i created a macro.... i need to check if the active work book has a sheet
named "xxx". do you know how should i do that?
thanks in advance.
 
M

Mike

Try this which is case sensitive

Sub isthereanybodythere()
Dim ws As Worksheet
msg = "What sheet are you looking for"
response = InputBox(msg)
For Each ws In ActiveWorkbook.Worksheets

Name = ws.Name
Worksheets(Name).Select
If response = Name Then

msg = Name + " Sheet exists"
MsgBox (msg)
End If

Next ws

End Sub
 
V

Vijay Chary

Miri said:
hi,
i created a macro.... i need to check if the active work book has a sheet
named "xxx". do you know how should i do that?
thanks in advance.

Hi ,
You could write a macro like the one shown below

Sub Surch()
a = Inputbox("Enter the name of the worksheet you want to search for:")
For each ws in worksheets
ws.select
If activesheet.name = a then
Msgbox ("This workbook has a sheet named " & a)
Goto last
Endif
Next
last:End Sub

This will do the trick

VJ
 
D

Dave Peterson

One more:

dim testWks as worksheet
set testwks = nothing
on error resume next
set testwks = activeworkbook.worksheets("xxx")
on error goto 0

if testwks is nothing then
'doesn't exist
else
'yep, it's there
end if
 
Top