+ Reply to Thread
Results 1 to 10 of 10

Naming Range Different Sheet

  1. #1
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2008
    Posts
    304

    Naming Range Different Sheet

    Hello,

    Im finding some problems in my code when trying to name ranges that are in a different sheet.

    Running the code in Sheet1 I want to execute the following code:

    Please Login or Register  to view this content.
    I don't know why but this code will only work if I run it in Sheet2 and not in Sheet1 that is where I would like it to do.

    Thanks for the help.

    Kind Regards,

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    You need a worksheet reference for Cells as well as Range.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

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

    Re: Naming Range Different Sheet

    Hi pezalmendra,

    When I record a macro to do what you are asking I get the following code:

    Please Login or Register  to view this content.
    I wonder if this code (recorded using 2013 excel) will work in your 2003 VBA?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2008
    Posts
    304

    Re: Naming Range Different Sheet

    Hello again and thanks for the reply,

    Couldn't make work any of both codes... Maybe it helps if I point out that Im running this code via a

    Please Login or Register  to view this content.
    The thing is that if I run the macro in the same sheet where I want to name the range (Sheet2) the code will work. If I run the code from a different sheet (Sheet1 in this case) it will give me an error.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Can you post all the code and explain how it doesn't work?

  6. #6
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2008
    Posts
    304

    Re: Naming Range Different Sheet

    Hello Norie,

    Here is the code:

    Please Login or Register  to view this content.
    Thanks,

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    So you didn't try the code I suggested?

  8. #8
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2008
    Posts
    304

    Re: Naming Range Different Sheet

    Yes, I tried it but with not success... I thought you wanted me to post the initial code I wrote.

  9. #9
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2008
    Posts
    304

    Re: Naming Range Different Sheet

    Hello again!

    I manage to solve the problem, just had to reference also in the cells inside the range the Sheet where the cells are:

    Please Login or Register  to view this content.
    Thanks for the help!!

    Regards,

  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: Naming Range Different Sheet

    The code I posted is just another way of writing that and it does work.
    Please Login or Register  to view this content.

+ 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