If Worksheets("Test") Exists Then Delete It

D

Don

Hi,

I want to do the above, but just can't work out how to do
it. If anyone has a piece of code that would work, I would
be very grateful.

Exists does not seem to work with the Worsheets.Item
object.

Don.
 
A

Abdul Salam

Try this:


Public Function ShExists(ShName As String) As Boolean
Dim WS As Worksheet

For Each WS In Workbooks _
(ActiveWorkbook.Name).Worksheets
If WS.Name = ShName Then
'If that sheet name exists
ShExists = True
Exit Function
End If

Next
ShExists = False
End Function

Abdul Salam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top