Solved

find sheet named ......

Posted on 2015-01-27
3
73 Views
Last Modified: 2015-01-28
Can an expert provide vba code that look to see if a sheet exists, if it does continue with my code and if not end sub

So I want to say:

look for sheet named Spain if it exists continue if it does not exist stop

Thanks
0
Comment
Question by:Jagwarman
3 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 200 total points
ID: 40574655
Hi,

pls try
On Error Resume Next
Set sh = ActiveWorkbook.Sheets("Spain")
On Error GoTo 0
If IsEmpty(sh) Then Exit Sub

Open in new window

Regards
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 200 total points
ID: 40574673
As an alternative:

If Not Evaluate("ISREF(Spain!A1)") Then Exit Sub

Open in new window

0
 
LVL 7

Assisted Solution

by:slubek
slubek earned 100 total points
ID: 40574749
Function WorksheetExists(ByVal WorksheetName As String) As Boolean
Dim Sht As Worksheet
    For Each Sht In ThisWorkbook.Worksheets
        If Application.Proper(Sht.Name) = Application.Proper(WorksheetName) Then
            WorksheetExists = True
            Exit Function
        End If
    Next Sht
    WorksheetExists = False
End Function

...
if WorksheetExists("Spain") then ...

Open in new window

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question