+ Reply to Thread
Results 1 to 5 of 5

Checking Worksheet Name

  1. #1
    Registered User
    Join Date
    01-03-2013
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    2

    Checking Worksheet Name

    Hi I am new to VBA and struggling to get a working code - getting error "sub or function not defined". I basically want to set up validation that there is no worksheet with the same name in the workbook. (the worksheet name is defined from a userform hence the cell reference C2.

    Dim stSheetName As String
    stSht = Range("C2")
    If Not bWorksheetExists(stSht) Then
    'Sheet does not exist
    'do something
    ActiveSheet.Name = Range("C2").Value

    Else
    'Sheet exists
    MsgBox "Details for this product already exist"
    End If

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Checking Worksheet Name

    Hello Kerrymcc
    Welcome to the forum.
    Take a moment to read the rules and learn how to enclose code snippets within code tags.
    As well as making your post easier to read/understand it also keeps the moderators at bay!
    Its always best to upload a working example to help us understand and debug your problem in context and also prevent long explanations and questions (like this post) and frustrations both ways.
    For example, in your code:
    .. you don't show a Sub name for your code - does it exist or not?
    .. you have DIMed stSheetName but you also need to DIM the other variables e.g. stSht and bWorksheetExists(stSht) before you use them
    So a bit more info please?
    If this was helpful then please click the small star icon at the bottom left of my post. A little appreciation goes a long way.

  3. #3
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Checking Worksheet Name

    See:

    https://groups.google.com/forum/?hl=...el/bi_JNLLlkfc
    Gary's Student

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Checking Worksheet Name

    you missed some code, the correct code is this
    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

  5. #5
    Registered User
    Join Date
    01-03-2013
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Checking Worksheet Name

    Hi,

    Thanks for the replies, this worked perfectly. Sorry for any confusion!

+ 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