+ Reply to Thread
Results 1 to 3 of 3

Range Based on Cell Values

  1. #1
    Registered User
    Join Date
    02-10-2008
    Posts
    13

    Range Based on Cell Values

    Let's say I wanted to take a sum of a range of cells. I want that range to be variable, based on other cell values. Specifically, I'm concerned with controlling the number of columns, and the 1st column will always be the same.

    For example:
    Cell A1 = 4, the number of columns to sum

    Random numbers to sum:
    A2 = 1
    A3 = 1
    B2 = 2
    B3 = 2
    C2 = 3
    C3 = 3
    D2 = 4
    D3 = 4

    What is the formula to take sum of the data based on the number of columns?

    If
    A1 = 4, sum(A2:D3)
    A1 = 3, sum (A2:C3)
    etc.

    For my current project, I am only focusing on columns, but I can see how using this type of reference would have many other uses. Thanks!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Range Based on Cell Values

    Try this formula out:

    =SUM(INDIRECT("$A$2:"&ADDRESS(3,A1)))
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Range Based on Cell Values

    I would nearly always opt for INDEX over INDIRECT given the latters volatility

    =SUM(A2:INDEX(A3:D3,A1))

+ 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