VBA check if sheet exists, if yes: select. If no select another sheet name

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
893
Office Version
  1. 365
Platform
  1. Windows
I need help with a code that can determine if a sheet name exists and do the following:

If exists: select the sheet and run a certain code
If it does not exist, select another sheet name and run a different code

Help with this code would be greatly appreciated.

Thank you
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Maybe something like
VBA Code:
Dim ShtName As String
ShtName = "Sheet 1"
If Evaluate("isref('" & ShtName & "'!A1)") Then
   'sheet exists do something
Else
   'sheet doesn't exist do something else
End If
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0
Maybe something like
VBA Code:
Dim ShtName As String
ShtName = "Sheet 1"
If Evaluate("isref('" & ShtName & "'!A1)") Then
   'sheet exists do something
Else
   'sheet doesn't exist do something else
End If
An additional question: are you able to do a 3rd condition that if the first 2 sheets do not exist do a 3rd code?
 
Upvote 0
How about
VBA Code:
Dim ShtName1 As String, ShtName2 As String
ShtName = "Sheet 1"
ShtName = "Sheet 2"
If Evaluate("isref('" & ShtName1 & "'!A1)") Then
   'sheet exists do something
ElseIf Evaluate("isref('" & ShtName2 & "'!A1)") Then
   'sheet doesn't exist do something else
Else
   'whatever
End If
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,800
Members
449,337
Latest member
BBV123

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