+ Reply to Thread
Results 1 to 7 of 7

use a variable within a range name

  1. #1
    Registered User
    Join Date
    09-18-2012
    Location
    Banbury, England
    MS-Off Ver
    Excel For Mac 2011
    Posts
    3

    use a variable within a range name

    Hello,
    I have code similar to the following:

    Please Login or Register  to view this content.
    What I want to do is create a range (Rng) depending on the value of i (here simply set to 5 for ease of reading). I know what I have written above is incorrect, but I just don't know how to fix it! Any thoughts much appreciated - thanks in advance.

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

    Re: use a variable within a range name

    To get A5 thru A7:


    Please Login or Register  to view this content.
    Gary's Student

  3. #3
    Registered User
    Join Date
    09-18-2012
    Location
    Banbury, England
    MS-Off Ver
    Excel For Mac 2011
    Posts
    3

    Re: use a variable within a range name

    Thanks, but I'm not sure if that does what I need it to...
    What I want is if i = 5 (for example), then Rng is equal to Row5, and if i=8, then Rng is equal to Row8.

    (by the way, 'Sub marine()' gave me a giggle)

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

    Re: use a variable within a range name

    Hi, tom_laight,

    one range or five different ones? This goes for one big range (at least on Windows ):

    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

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

    Re: use a variable within a range name

    I apologize for the humour.

    In your example, Row5 is the name of a distinct range. To access it from a group of ranges, you need an array of ranges:


    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-18-2012
    Location
    Banbury, England
    MS-Off Ver
    Excel For Mac 2011
    Posts
    3

    Re: use a variable within a range name

    I think that's cracked it! Thanks very much to both of you for your swift and helpful replies - I'll be coming here again

    Tom

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

    Re: use a variable within a range name

    @ tom_laight

    Welcome to the forum.

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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