+ Reply to Thread
Results 1 to 7 of 7

how to refer a sheet by its name

  1. #1
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    Angry how to refer a sheet by its name

    how to refer a sheet in a code
    activesheet is working but when i use Sheets("Sheet3") or WorkSheets("Sheet3").

    It throws "Run time Error 9"

    Help its gettin me nuts

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: how to refer a sheet by its name

    Use Worksheets("Sheet3") and not Sheets("Sheet3")

    If you don't have a "Sheet3" then you can use a number in the parenthesis.
    Worksheets(1) is the farthest one on the left.

    If you want to check it's name you can call it by using Worksheets(1).name.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: how to refer a sheet by its name

    Can you explain me some standard procedure for referring to worksheets, workbook because sometimes the references work fine when i do it in my system but when i do it on another system it throws an error.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: how to refer a sheet by its name

    Sheets("Sheet3") will work if you have a sheet with that name in the active workbook-unless the code is in the thisworkbook module of a workbook in which case the sheet must be in the same workbook as the code unless you specify which workbook you are referring to (which is better anyway)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    02-20-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: how to refer a sheet by its name

    okk thanks for tip i will try it....

    but this code which was working perfectly fine but now is giving runtime error 32809 application defined or object defined error.

    Private Sub CommandButton3_Click()
    Worksheets(ActiveSheet.Index + 1).Activate
    End Sub

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: how to refer a sheet by its name

    can you post a workbook that exhibits that problem? are there any chart sheets in the workbook

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: how to refer a sheet by its name

    If your ActiveSheet is the last sheet you will get an error with your code. Perhaps this is why it works sometimes and not others?

+ 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