Solved

VBA - Check a tab exists in another sheet

Posted on 2014-07-30
4
169 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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 in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

758 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

22 Experts available now in Live!

Get 1:1 Help Now