Solved

VBA - Check a tab exists in another sheet

Posted on 2014-07-30
4
180 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
[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
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

623 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