excel sum till a specific number

Tomaž Podgornik

I am a total noob on excel so here i am looking for answers.

Best to explain this on a example.

I have in a row numbers from 1-1000000. I would like to sum them till 1000.

How do you do that?

Gary's Student

With values in row #1, in A2 enter:

=A1

In B2 enter:

=IF(A2="","",IF((A2+B1>1000),"",A2+B1))

and copy across. Finally in A3 enter:

=LOOKUP(88^99,2:2)

For example:

enter image description here

EDIT#1:

To avoid the "Helper" column, I would use the following UDF:

Public Function SumUntil(rIn As Range, Limit As Double) As Double
    Dim r As Range, t As Double
    SumUntil = 0
    For Each r In rIn
        t = SumUntil
        SumUntil = SumUntil + r.Value
        If SumUntil > Limit Then
            SumUntil = t
            Exit Function
        End If
    Next r
End Function

User Defined Functions (UDFs) are very easy to install and use:

  1. ALT-F11 brings up the VBE window
  2. ALT-I ALT-M opens a fresh module
  3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx

To remove the UDF:

  1. bring up the VBE window as above
  2. clear the code out
  3. close the VBE window

To use the UDF from Excel:

=SumUntil(1:1,1000)

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

and for specifics on UDFs, see:

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx

Macros must be enabled for this to work!

EDIT#2:

To count the number of values that were summed, I would use a different UDF:

Public Function CountUntil(rIn As Range, Limit As Double) As Long
    Dim r As Range, t As Double, i As Long
    Dim SumUntil As Double
    SumUntil = 0
    i = 0
    For Each r In rIn
        i = i + 1
        t = SumUntil
        SumUntil = SumUntil + r.Value
        If SumUntil > Limit Then
            CountUntil = i - 1
            Exit Function
        End If
    Next r
End Function

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

sum of digits till the sum is one-digit number

From Dev

find sum of numbers in a column up till a specified number

From Dev

Sum the number of hours in Excel

From Dev

Excel: How do I sum specific number of cells to the right of a name throughout an entire sheet?

From Dev

Finding sum of number nearest to specific number

From Dev

Integer verification and sum till it in js

From Dev

Integer verification and sum till it in js

From Dev

Filter Specific Column Number in Excel

From Dev

Go to specific row number in excel

From Dev

MYSQL sum of a column with some specific number of entries

From Dev

Split the string till specific substring

From Dev

Sum the values from the days in a specific week in Excel

From Dev

Return number of days till nowday

From Dev

how to sum positive (+) and negative (-) number in excel

From Dev

Excel Array Function to Sum a number of COUNTIF statements

From Dev

Sum number of record between dates Excel

From Dev

Sum of number of times unique value appears in Excel

From Dev

calculate the sum of all the digits of number till you get a single digit in java script r give idea to improve below program

From Dev

Cumulative sum of variable till a given percentile

From Dev

Cumulative sum of variable till a given percentile

From Dev

Excel validation number from specific characters

From Dev

Microsoft Excel, adding a specific number to a column

From Dev

How to increment cell range by a specific number [Excel]

From Dev

Change the specific text become a number in excel

From Dev

Excel Data validation with whole number and specific text

From Dev

grep - regular expression - match till a specific word

From Dev

Momentjs seconds from now till a specific hour

From Dev

How to fill a DataFrame till specific row?

From Dev

vba loop till a specific value is found

Related Related

  1. 1

    sum of digits till the sum is one-digit number

  2. 2

    find sum of numbers in a column up till a specified number

  3. 3

    Sum the number of hours in Excel

  4. 4

    Excel: How do I sum specific number of cells to the right of a name throughout an entire sheet?

  5. 5

    Finding sum of number nearest to specific number

  6. 6

    Integer verification and sum till it in js

  7. 7

    Integer verification and sum till it in js

  8. 8

    Filter Specific Column Number in Excel

  9. 9

    Go to specific row number in excel

  10. 10

    MYSQL sum of a column with some specific number of entries

  11. 11

    Split the string till specific substring

  12. 12

    Sum the values from the days in a specific week in Excel

  13. 13

    Return number of days till nowday

  14. 14

    how to sum positive (+) and negative (-) number in excel

  15. 15

    Excel Array Function to Sum a number of COUNTIF statements

  16. 16

    Sum number of record between dates Excel

  17. 17

    Sum of number of times unique value appears in Excel

  18. 18

    calculate the sum of all the digits of number till you get a single digit in java script r give idea to improve below program

  19. 19

    Cumulative sum of variable till a given percentile

  20. 20

    Cumulative sum of variable till a given percentile

  21. 21

    Excel validation number from specific characters

  22. 22

    Microsoft Excel, adding a specific number to a column

  23. 23

    How to increment cell range by a specific number [Excel]

  24. 24

    Change the specific text become a number in excel

  25. 25

    Excel Data validation with whole number and specific text

  26. 26

    grep - regular expression - match till a specific word

  27. 27

    Momentjs seconds from now till a specific hour

  28. 28

    How to fill a DataFrame till specific row?

  29. 29

    vba loop till a specific value is found

HotTag

Archive