+ Reply to Thread
Results 1 to 13 of 13

Check to see if sheet exists

  1. #1
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Check to see if sheet exists

    Hi again

    Help with ON error, I have a userform textbox that a user can name a new sheet which is copied from a master template sheet, my problem is if the name already exists it errors out, I have had a go with on error resume next, have searched here but I admit I am struggling with such a simple task, all I want is basically if the new name(sheet) from Textbox1 value already exists then msgbox to "try different name", thanks in advance.....code below

    Please Login or Register  to view this content.

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

    Re: Check to see if sheet exists

    Add this code in your form...

    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

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Check to see if sheet exists

    Untested.

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Check to see if sheet exists

    You can perform a check if the Sheet name exists or not, use the following function created by Tim Williams. It basically doesn't involve any loops so saves your memory on CPU.

    Please Login or Register  to view this content.
    This function returns -1 if sheet exists and 0 if it doesn't.
    cOdEsLiZeR - Back after a long break.. Let's sLiZe some more cOdEs!!

  5. #5
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: Check to see if sheet exists

    Thanks guys

    Sixthsense your code seems to work in reverse....it brings up the msgbox on sheets name that DONT exist not on ones that do
    AB33 your code does kinda work the msgbox comes up on duplicate sheet names but after clicking ok it runs the rest of my code and makes a copy of the template sheet

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Check to see if sheet exists

    AB33 your code does kinda work the msgbox comes up on duplicate sheet names but after clicking ok it runs the rest of my code and makes a copy of the template sheet

    I thought is not that what you want.
    The code tests if sheet exists, it does not, it names the active sheet using the name of textbox. If it does exist, it skips and you get a message.

  7. #7
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: Check to see if sheet exists

    Thanks for trying guys but I can not get any of the above coding to work with mine, hopefully my users will not input a duplicate name lol

  8. #8
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Check to see if sheet exists

    Well, If you say, AB33's code work for you, then I believe you just need to Unload the form once the message box is shown, so that it won't perform the rest of the task.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: Check to see if sheet exists

    Thanks codeslizer

    I had already tried that and thought that would have been too easy, didnt work, I didnt think finding a small bit of code to check sheet names would be so difficult lol I am sure they work with other peoples bits of code, I guess the way I am doing the naming of a sheet using a userform and textbox makes it a little harder to get it all to blend together


    Thanks

  10. #10
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Check to see if sheet exists

    Hey Jet,

    I have worked out on a sample for your references. Check out the attached file. It contains a userform that renames the sheet names. For this purpose, I have used the same IfSheetExists() function to check if the sheet name already exists and if doesn't then simply renames the selected sheet. I have also created a macro to get the list of available sheets so I can keep a tab on which ones are already available and if no renames are performed, I can skip the operations.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: Check to see if sheet exists

    Thank you codeslizer, I can use this

    Thanks for taking the time to help me

  12. #12
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Check to see if sheet exists

    Sure no problem, it's great to know that we're able to help!

    Don't forget to mark the thread as Solved and add reputations to those whom you find helpful.

  13. #13
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: Check to see if sheet exists

    Done codeslizer

+ 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. Replies: 1
    Last Post: 05-29-2013, 01:20 PM
  2. [SOLVED] check if sheet exists, if not then create
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-06-2013, 06:12 AM
  3. Check to see if a sheet exists
    By michaelbails in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-26-2010, 01:08 AM
  4. check if the sheet/tag exists
    By Alex in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-14-2006, 05:10 PM
  5. How to check from VBA if sheet exists?
    By Alen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-02-2006, 08:40 AM

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