+ Reply to Thread
Results 1 to 5 of 5

how do I validate sheet names?

Hybrid View

jojotherider how do I validate sheet names? 04-04-2008, 05:57 PM
there_is_no_bob What do you want to do in the... 04-04-2008, 06:31 PM
jojotherider good question... Part of... 04-04-2008, 07:04 PM
rylo Hi You could build your... 04-04-2008, 07:18 PM
jojotherider That works perfect. Thank... 04-07-2008, 12:27 PM
  1. #1
    Registered User
    Join Date
    06-22-2005
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    40

    how do I validate sheet names?

    Hi,

    I've got a macro that creates sheets based on a list of names in sheet1. If the user goes back to the macro a second time (i.e. there are already named sheets), how can prevent them from creating another sheet that already exists. Currently, when I create the new sheet and try to rename it, I get an error if there is already a sheet with that name.

    eh, hope that makes sense.

    -joel

  2. #2
    Registered User
    Join Date
    04-02-2008
    Posts
    3
    What do you want to do in the case of an already existing sheet?

    Do you have a variable that points to the sheet you're trying to rename?

  3. #3
    Registered User
    Join Date
    06-22-2005
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    40
    good question...

    Part of me wants to just exit the sub and make the user remove it and start over. But then that will probably lead to more duplicates.

    I think displaying a message box indicating so would be good enough and then continuing with the script.

    -joel

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    You could build your own function along the lines of
    Function SheetExists(sh) As Boolean
      SheetExists = False
      On Error Resume Next
      Set sht = Sheets(sh)
      On Error GoTo 0
      If Not IsEmpty(sht) Then SheetExists = True
    End Function
    and incorporate this in your code.
    sub tester
      if not sheetexists("sheet1") then
       'process your code
      end if
    end sub
    hth

    rylo

  5. #5
    Registered User
    Join Date
    06-22-2005
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    40
    That works perfect. Thank You!

    I've never really written my own functions like that where you have to pass a value to it. I just learned that you could do that the other day.

    -joel

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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