Checking existance of a Sheet


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Checking existance of a Sheet

  1. #1
    Join Date
    Feb 2006
    Posts
    6

    Checking existance of a Sheet

    Hi ,

    I have small problem in Excel macro.

    I am trying to do two processes based on existance of sheet.
    If sheet exist i will perform process 1 and if sheet does not exist then process2.

    i am using following code

    Sheets("activity").select

    but the sheet "activity" does not exist. error i got is "subscript out of range".
    I want trap(skip) this error and proceed further. I need a fucntion which can give output whether sheet exist or not.

    can somebody help me ?

    Thanks in advance.

    Rajesh

  2. #2
    Join Date
    Feb 2006
    Posts
    133
    Try this:

    Code:
    Private Sub CommandButton1_Click()
        MsgBox SheetExist("activity")
    End Sub
    
    Private Function SheetExist(strSheet As String) As Boolean
        On Error GoTo Errorhandling
        Sheets(strSheet).Select
        SheetExist = True
        Exit Function
        
    Errorhandling:
        SheetExist = False
    End Function
    The function sheetexist gives back true if the sheet exists.
    This is one solution, there are probably other.

    Benjamin

  3. #3
    Join Date
    Feb 2006
    Posts
    6
    Hi Benjamin,
    Thanx for your suggestion.

    Its working now.

    Regards,
    Rajesh

Similar Threads

  1. Style Sheet Problem with Websphere
    By cmorrell in forum Java
    Replies: 0
    Last Post: 09-01-2005, 09:12 AM
  2. Replies: 0
    Last Post: 07-16-2002, 11:28 PM
  3. Style Sheet Caching
    By Dan in forum Web
    Replies: 7
    Last Post: 05-20-2002, 01:32 PM
  4. Need Help with VBA for Excel
    By Bob in forum VB Classic
    Replies: 0
    Last Post: 03-14-2002, 02:27 PM
  5. Replies: 5
    Last Post: 01-08-2001, 06:40 PM

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