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

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
888
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

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
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,108
Messages
6,123,133
Members
449,098
Latest member
Doanvanhieu

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