Determine if Worksheet Exists


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Determine if Worksheet Exists

  1. #1
    Join Date
    Aug 2007
    Posts
    58

    Question Determine if Worksheet Exists

    I have the following Code:

    Code:
    With ActiveSheet
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
        Worksheets(2).Select
        Range("A1:F85").Select
        Selection.Copy
        Sheets(1).Select
        Range("A" & LastRow).Select
        ActiveSheet.Paste
        Range("A1").Select
        End With
        
        With ActiveSheet
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
        Worksheets(3).Select
        Range("A1:F85").Select
        Selection.Copy
        Sheets(1).Select
        Range("A" & LastRow).Select
        ActiveSheet.Paste
        Range("A1").Select
        End With
        
        With ActiveSheet
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
        Worksheets(4).Select
        Range("A1:F85").Select
        Selection.Copy
        Sheets(1).Select
        Range("A" & LastRow).Select
        ActiveSheet.Paste
        Range("A1").Select
        End With
    I need a way to tell the macro to run only if the worksheet exist. For example, if Worksheet(4) does not exist, then I do not want that portion of the code above to run.

  2. #2
    Join Date
    Aug 2005
    Location
    Hermosillo, Sonora, Mexico
    Posts
    103
    'Declarations
    Dim xls As Excel.Application
    Dim xlswbook As Excel.Workbook

    'Instantiate
    Set xls = New Excel.Application
    Set xlswbook = xls.Workbooks.Open("SomeXlsFile")

    'Navigate thru all sheets
    For I = 1 To xlswbook.Sheets.Count
    MsgBox xlswbook.Sheets(I).Name
    Next I

Similar Threads

  1. Check if file exists
    By John Knoop in forum .NET
    Replies: 8
    Last Post: 02-28-2010, 02:57 PM
  2. Bug with Creation of Objects in SQL *Plus Worksheet
    By Michael Cole in forum Database
    Replies: 2
    Last Post: 04-02-2003, 04:06 PM
  3. A question about EXISTS
    By Richard Hart in forum Database
    Replies: 6
    Last Post: 01-09-2002, 02:50 PM
  4. How to determine if "string" exists in Database?
    By Bassel Tabbah in forum VB Classic
    Replies: 2
    Last Post: 09-13-2001, 06:55 AM
  5. determining if a table exists
    By Jon in forum Database
    Replies: 2
    Last Post: 05-11-2000, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center