Solved

find sheet named ......

Posted on 2015-01-27
3
71 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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel case statements 3 24
Fixing a embedded format 7 29
Error in VBA for exact date format as in source file 9 27
Excel range I cannot find 8 22
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now