+ Reply to Thread
Results 1 to 8 of 8

Using a variable number of cells in SUM function

  1. #1
    Registered User
    Join Date
    01-30-2014
    Location
    Brazil
    MS-Off Ver
    Excel 2016
    Posts
    46

    Question Using a variable number of cells in SUM function

    Hello everyone.
    Here's my problem: I need to sum some adjacent cells in a column, but the number of cells varies (according to a value in another cell). In the SUM function you need to specify all the cells. Is there a way to solve this?
    If it can't be done, I guess I'll need to do it via VBA right?
    Thanks!

  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
    45,205

    Re: Using a variable number of cells in SUM function

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    B2 contains the start cell/column; C2 contains the number of cells/columns.


    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
    01-30-2014
    Location
    Brazil
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Using a variable number of cells in SUM function

    Hello TMS!
    I'm getting a "The formula you typed contains an error.".
    Can you help me understand your formula? I can see that it's possible to reference to a cell, but I'm not getting the whole thing.
    I'm updating an excel file so you can better undersand my problem, can you apply that formula on that sheet?
    Thank you very much for the attention!

    Help.xlsx

  4. #4
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Using a variable number of cells in SUM function

    This is simple but might suit:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by newdoverman; 03-14-2014 at 04:11 PM.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  5. #5
    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
    45,205

    Re: Using a variable number of cells in SUM function

    Cell D2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and copy down.

    Or

    Cell D2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Variations on a theme depending on your data structure.



    See the updated example attached
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    01-30-2014
    Location
    Brazil
    MS-Off Ver
    Excel 2016
    Posts
    46

    Re: Using a variable number of cells in SUM function

    newdoverman, that works! Just had to make some adjustments.
    And TMS, your solution worked too!
    Thank you both for the attention!

  7. #7
    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
    45,205

    Re: Using a variable number of cells in SUM function

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  8. #8
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Using a variable number of cells in SUM function

    Thank you for the feedback. I am curious as to the amendments you made to make the proposed solution fit your problem.

+ 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. [SOLVED] using Countif Function: Column number stored in a variable
    By vidyuthrajesh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2014, 06:58 PM
  2. Summing a variable number of cells
    By rschammel in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-30-2013, 02:55 AM
  3. Averaging Variable Number of Cells
    By MaxM&M in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-26-2013, 09:01 PM
  4. Sum a variable number of cells
    By lhmome in forum Excel General
    Replies: 11
    Last Post: 05-02-2009, 02:31 AM
  5. Hyperlink function fails when using variable row number
    By Balex in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-08-2006, 01:45 AM

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