+ Reply to Thread
Results 1 to 8 of 8

range variable

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    suffolk, england
    MS-Off Ver
    Excel 2007
    Posts
    5

    range variable

    the issue of how to reference a cell using a variable has been covered previously using INDIRECT and ADDRESS but I am trying to use a variable that refers to a cell range within a function e.g. =SUM(A1:A5) where I would like to replace "A1:A5" with a cell location which contains the cell range as the function I am using is in many places on the spreadsheet and it would be tedious to have to edit every formula that contains the cell range to change it to another cell range...any ideas?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,433

    Re: range variable

    =SUM(INDIRECT(D1))

    where cell D1 contains A1:A5

    Can't help thinking that if you have to edit a cell so that all your formulae referencing a range are updated, it could do with re-engineering. Can you not specify a dynamic named range?

    Regards, TMS

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-01-2012
    Location
    suffolk, england
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: range variable

    Thanks TMS I should have made my problem clearer and more specific as the cell range I am trying to make into a variable is contained within a function which refers to another worksheet in the form of FUNCTION('WORKSHEET!A1:A5')and excel returns an error if i try to use a function like INDIRECT within a reference to another worksheet

  4. #4
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: range variable

    TMS' formula should still work as long as input in D1 is WORKSHEET!A1:A5

    Is 'worksheet' a separate worbook or separate worksheet in the same workbook?
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  5. #5
    Registered User
    Join Date
    10-01-2012
    Location
    suffolk, england
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: range variable

    its a worksheet in the same workbook. i tried using the full cell range reference NAME!A1:A5 but alas still an error, I also tried putting single quotes around 'NAME' but still no joy.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,433

    Re: range variable

    Sheet2!A1:A5 in cell D1 works just fine for me.

    C1: =SUM(INDIRECT(D1)) = 30
    D1: Sheet2!A1:A5

    Sheet2:A1:A5 = 2, 4, 6, 8, 10

    If you put single quotes around the sheet name, the first one will be interpreted by Excel as the cell being Text and you will get a #REF! error. The implication is that you would struggle to have a reference where the sheet name had a space in it.


    Regards, TMS

  7. #7
    Registered User
    Join Date
    10-01-2012
    Location
    suffolk, england
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: range variable

    Thanks for your patience on this. I had tried exaclty what you had suggested and I am now wondering whether it is something to do with the particular function I am using which is SUMIFS rather than just SUM ( I only used SUM in my original post as I though it would simplify matters but maybe thats not the case.

  8. #8
    Registered User
    Join Date
    10-01-2012
    Location
    suffolk, england
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: range variable

    I have just re-read your post and double checked my sheet name and it does have a space in the name and within my spreadsheet where I am using the function SUMIFS the worksheet does have single quotes around the two word sheet name.

+ 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