+ Reply to Thread
Results 1 to 12 of 12

Using Codename in VBA

  1. #1
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Using Codename in VBA

    I thought I could use the codename ("sheet1") instead of the actual sheet name ("sales") in VBA so if the sheet name was changed it would not affect the macro. Am I wrong or am I doing something wrong. I have tried it with and without the "" around it. ???? Please help!

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Using Codename in VBA

    Hi, backyardfun,

    correct syntax should be
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using Codename in VBA

    Or you can use the order of the sheet

    Please Login or Register  to view this content.
    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Using Codename in VBA

    Hi, abousetta,

    just for being curious: what will happen if Sheets(1) is a chart? You should at least recommend to use Worksheets(1).

    Ciao,
    Holger

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using Codename in VBA

    Have you ever seen a chart called "Sheet1"? Can't say that I have

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Using Codename in VBA

    Hi, abousetta,

    where do you pick up the name of the sheet? You just refer to the very first sheet in the workbook with Sheets(1) regardless of any name - please correct me if I got the fundamentals wrong.

    Ciao,
    Holger

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using Codename in VBA

    From the first post...

    Quote Originally Posted by backyardfun View Post
    I thought I could use the codename ("sheet1") instead of the actual sheet name ("sales") in VBA

  8. #8
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Using Codename in VBA

    It doesn't matter in what order or whatever the name is
    Please Login or Register  to view this content.
    Last edited by HSV; 12-22-2013 at 10:01 AM.
    Kind regards, Harry.

  9. #9
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Using Codename in VBA

    I keep getting a run-time error 9, script out of range, and it highlights the first line with the codename ("sheet2") in it. ??????


    Please Login or Register  to view this content.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Using Codename in VBA

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  11. #11
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using Codename in VBA

    If you are going to use the codename then it's:

    Please Login or Register  to view this content.
    abousetta

  12. #12
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Using Codename in VBA

    got it. thanks

+ 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. sheet codename issue
    By elprup in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-18-2010, 02:37 PM
  2. Get sheet (CodeName) not .Name
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-14-2010, 01:54 PM
  3. .CodeName inconsistency
    By paulharvey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2007, 02:23 PM
  4. VBA codename and codeprotection
    By CoCo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-09-2006, 11:49 PM
  5. [SOLVED] codename help
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-30-2005, 09:05 PM

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