Check if sheets exist

oldham94l

Board Regular
Joined
Jul 14, 2002
Messages
136
i need a macro to check specified sheet names exist, eg "menu" "data" "mail" etc

if any sheets are missing then a macro will run.

thanks
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi;

You may try this if it helps;

Option Base 1
Sub CheckWB()
Dim CheckShName(3) As String, i As Integer, j As Integer
CheckShName(1) = "menu"
CheckShName(2) = "data"
CheckShName(3) = "mail"
For j = 1 To 3
For i = 1 To Worksheets.Count
If Sheets(i).Name <> CheckShName(j) Then
YourMacro
Exit Sub
End If
Next
Next
End Sub
 
Upvote 0
One way:

<pre>
Function SheetPresent(ByVal aName As String) As Boolean
On Error Resume Next
SheetPresent = Not (ActiveWorkbook.Sheets(aName) Is Nothing)
End Function

Sub testSheetPresent()
MsgBox SheetPresent("sheet1") _
& ", " & SheetPresent("no such sheet")
End Sub

</pre>
 
Upvote 0
Another method (there are loads of ways to do this)


Function SheetExists(sheetName As String) As Boolean

Dim iSheet As Object

For Each iSheet In Sheets

If UCase(iSheet.Name) = UCase(sheetName) Then

SheetExists = True

Exit Function

End If

Next iSheet

End Function
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top