+ Reply to Thread
Results 1 to 10 of 10

Need to check if worksheet exists and execute code

  1. #1
    Forum Contributor
    Join Date
    07-08-2012
    Location
    beirut
    MS-Off Ver
    Excel 2010
    Posts
    102

    Need to check if worksheet exists and execute code

    Hey all,
    Need help with my workbook.
    In the summary sheet, columns A and B are players names, which are retrived from a list
    I have several worksheets named after some players names,
    when I enter in column A the name "John" and in column B the name "Joe" for example, and i fill the row with information, and I type BAB in the L column, this code automatically copies the data to worksheet named "John" and to worksheet named "Joe" and makes some adjustments.
    The problem is I need help to bypass the error generated when I enter a name in column A or B that does not have a worksheet named after it.
    I need to edit the code to be able to check wether the worksheet of the player exists, if true then continue the code, if not then display a message box saying that the worksheet "player name" does not exist.
    Thanks

    Please Login or Register  to view this content.
    Last edited by Cutter; 09-23-2012 at 10:34 AM. Reason: Added code tags

  2. #2
    Registered User
    Join Date
    09-20-2012
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Need to check if worksheet exists and execute code

    Your code should look like this (and use the Code tag next time you paste code!):

    Please Login or Register  to view this content.
    Last edited by blobbles; 09-23-2012 at 09:42 PM. Reason: Incorrect code

  3. #3
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Need to check if worksheet exists and execute code

    @ chiidzzz

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
    Thanks.

  4. #4
    Forum Contributor
    Join Date
    07-08-2012
    Location
    beirut
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: Need to check if worksheet exists and execute code

    Thank you blobbles, but your code is returning an error, I think the problem is with this part:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-20-2012
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Need to check if worksheet exists and execute code

    Sorry, try this:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    07-08-2012
    Location
    beirut
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: Need to check if worksheet exists and execute code

    still getting error 9 subscript out of range

  7. #7
    Registered User
    Join Date
    09-20-2012
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Need to check if worksheet exists and execute code

    Which line of code is highlighted when you click "Debug" when you see this error message? I just tested the code I wrote and it looks fine...

  8. #8
    Forum Contributor
    Join Date
    07-08-2012
    Location
    beirut
    MS-Off Ver
    Excel 2010
    Posts
    102

    Re: Need to check if worksheet exists and execute code

    this one
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    09-20-2012
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Need to check if worksheet exists and execute code

    OK, the problem with your code is that you can't have an "a" when you use the ....Cells(Rows.Count, "a")... you need to use a number instead. So it should read:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-20-2012
    Location
    Wellington, New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Need to check if worksheet exists and execute code

    That's a tip, you can only use .... Range("A" & RowNumber)... when referencing a column using the "A,B,C" etc notation. When using the Cells syntax you need to use row numbers and column numbers, something like ....Cells(1,3)...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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