Solved

VBA - Check a tab exists in another sheet

Posted on 2014-07-30
4
173 Views
Last Modified: 2014-07-30
Hi,

I want to check to see if a tab exists in a wb xyz.xls called "Combined Data"

If it does not, do nothing, carry on

if it does, message box "Error, new data not saved", then exit sub

Thanks
0
Comment
Question by:Seamus2626
  • 2
  • 2
4 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40229202
so this will be a different workbook then the active one?
0
 

Author Comment

by:Seamus2626
ID: 40229205
Yes, thanks
0
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
ID: 40229218
Sub CheckPageinWB()
    Dim xls As Excel.Worksheet
    Dim xlb As Excel.Workbook
    Dim hassheet As Boolean
    hassheet = False
    
    Set xlb = Workbooks.Open("xyz.xls")
    For Each xls In xlb.Worksheets
        If xls.Name = "Combined Data" Then
            hassheet = True
            Exit For
        End If
    Next
    xlb.Close False
    If (hassheet) Then MsgBox "Error, new data not saved"
End Sub

Open in new window

0
 

Author Closing Comment

by:Seamus2626
ID: 40229229
Thanks Randy
0

Featured Post

Industry Leaders: 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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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 how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

685 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