memberlogin
Technical User
How can I find out if an Excel worksheet exists before running a macro so as to avoid an error?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Err.Clear
Option Explicit
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 19/06/2003 by Bryan Bayfield
'
Dim wkbIterate As Workbook, wksIterate As Worksheet, strList As String
strList = "?"
For Each wkbIterate In Application.Workbooks
For Each wksIterate In wkbIterate.Sheets
strList = strList & wksIterate.Name & "?"
Next
Next
Select Case InStr(strList, InputBox("Select a sheet name to search for"))
Case 0
Debug.Print "That sheet doesn't exist"
Case Else
Debug.Print "Sheet exists"
End Select
End Sub