+ Reply to Thread
Results 1 to 4 of 4

How to find whether a worksheet exists in a workbook (getting frustated really!!!)

  1. #1
    Registered User
    Join Date
    10-08-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    4

    How to find whether a worksheet exists in a workbook (getting frustated really!!!)

    Hi, I am trying the following:

    Sub FindState(LocalState As String)

    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets

    If ws.Name <> LocalState Then

    MsgBox "The state does not exist", vbExclamation

    End
    End If
    Next

    End Sub

    But the problem is that whether the worksheet with the state name exists or not, it goes through the message1!!!!
    Any advice is appreciated

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How to find whether a worksheet exists in a workbook (getting frustated really!!!)

    Hi, kgakhar,

    please use code-tags when showing your procedures here on ExcelForum.

    Please Login or Register  to view this content.
    Or Google for Function WorksheetExists which will return a boolean to either match or not a state.

    CIao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,767

    Re: How to find whether a worksheet exists in a workbook (getting frustated really!!!)

    Make use of Error Handler and try like this...

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How to find whether a worksheet exists in a workbook (getting frustated really!!!)

    Hi, kgakhar,

    you may use any of the codes from http://www.excelforum.com/excel-prog...ml#post3415218 as well (no need to add a sheet and rename it).

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find workbook name and combine that workbook into exisiting worksheet column
    By ghladik in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2013, 02:23 PM
  2. Replies: 4
    Last Post: 10-25-2012, 05:09 PM
  3. Replies: 1
    Last Post: 10-24-2012, 07:46 AM
  4. Macro to Find if a certain worksheet exists
    By BigDubbe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2008, 04:48 PM
  5. [SOLVED] Find a value in a workbook and return the worksheet name
    By Craig in forum Excel General
    Replies: 2
    Last Post: 08-10-2005, 05:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1