Solved

find sheet named ......

Posted on 2015-01-27
3
75 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 51

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

724 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