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
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Haluk

Rules Violation
Joined
Oct 26, 2002
Messages
1,075
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
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
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>
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,809
Messages
5,598,202
Members
414,218
Latest member
speedbit

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
Top