+ Reply to Thread
Results 1 to 18 of 18

Return Numerical Label for LAST value Subtracted to reach Sum Target Value

  1. #1
    Sam via OfficeKB.com
    Guest

    Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi All,

    I am looking for a Formula that can process the following:

    The Sum Target Value is variable e.g.; 147
    I have two columns of numerical values: Column “A” and Column “B.”
    Column “A” Houses the Numerical Labels that I wish to have Returned when the
    Sum Target Value is processed /reached - Subtract Sum Target Value as noted
    below.

    To Subtract Sum Target Value:
    Start from LAST non-zero numerical value in Column “B” and Subtract one Cell
    value at a time (or Sum up the Column) until the Sum Target Value or nearest
    possible Sum BELOW, the Sum Target Value is reached. In this instance, it is
    147. I wish to Sum the values in Column “B” to 147 per the above. The
    summed values can be below BUT NOT over the Sum Target Value.

    Return the Numerical Value that is Offset ONE Cell to the LEFT (Column “A”)
    and ONE Row Above LAST value Subtracted (in Column “B”) to reach Sum Target
    Value. The Result – Numerical Label should come from Column “A.”


    Col “A” Col “B”
    200 3
    205 1
    210 5
    215 11
    220 10
    225 15
    230 16
    235 10
    240 11
    245 29
    250 20
    255 27
    260 22
    265 34
    270 24
    275 36
    280 30
    285 25
    290 31
    295 26
    300 15
    305 18
    310 23
    315 17
    320 9
    325 11
    330 2
    335 9
    340 1
    0 0

    Reaching the Sum Target Value of 147 in Column “B” would go up to value 26,
    Label 295 in Column “A”, totalling 131 which is below the Sum Target 147 but
    including the value of 31 above it, would exceed the Sum Target Value of 147.
    The required Result is returned from Column “A” Label 290 which is ONE Cell
    to the LEFT (Column “A”) and ONE Row Above LAST value Subtracted (in Column
    “B”).

    Thanks
    Sam


    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...tions/200510/1

  2. #2
    Ron Rosenfeld
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    On Fri, 28 Oct 2005 21:01:37 GMT, "Sam via OfficeKB.com" <u4102@uwe> wrote:

    >Hi All,
    >
    >I am looking for a Formula that can process the following:
    >
    >The Sum Target Value is variable e.g.; 147
    >I have two columns of numerical values: Column “A” and Column “B.”
    >Column “A” Houses the Numerical Labels that I wish to have Returned when the
    >Sum Target Value is processed /reached - Subtract Sum Target Value as noted
    >below.
    >
    >To Subtract Sum Target Value:
    >Start from LAST non-zero numerical value in Column “B” and Subtract one Cell
    >value at a time (or Sum up the Column) until the Sum Target Value or nearest
    >possible Sum BELOW, the Sum Target Value is reached. In this instance, it is
    >147. I wish to Sum the values in Column “B” to 147 per the above. The
    >summed values can be below BUT NOT over the Sum Target Value.
    >
    >Return the Numerical Value that is Offset ONE Cell to the LEFT (Column “A”)
    >and ONE Row Above LAST value Subtracted (in Column “B”) to reach Sum Target
    >Value. The Result – Numerical Label should come from Column “A.”
    >
    >
    >Col “A” Col “B”
    >200 3
    >205 1
    >210 5
    >215 11
    >220 10
    >225 15
    >230 16
    >235 10
    >240 11
    >245 29
    >250 20
    >255 27
    >260 22
    >265 34
    >270 24
    >275 36
    >280 30
    >285 25
    >290 31
    >295 26
    >300 15
    >305 18
    >310 23
    >315 17
    >320 9
    >325 11
    >330 2
    >335 9
    >340 1
    >0 0
    >
    >Reaching the Sum Target Value of 147 in Column “B” would go up to value 26,
    >Label 295 in Column “A”, totalling 131 which is below the Sum Target 147 but
    >including the value of 31 above it, would exceed the Sum Target Value of 147.
    >The required Result is returned from Column “A” Label 290 which is ONE Cell
    >to the LEFT (Column “A”) and ONE Row Above LAST value Subtracted (in Column
    >“B”).
    >
    >Thanks
    >Sam


    Here's one way that'll get you the correct answer. It involves adding a third
    column:

    C1: =SUM(B1:$B$30)

    Then copy/drag down to C30.

    The formula that will return the Label would then be:

    =INDEX(A1:A30,MATCH(target_value,C1:C30,-1)+(COUNTIF(C1:C30,target_value)=0))


    --ron

  3. #3
    Domenic
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Try the following...

    First, define dynamic ranges for Column A and Column B...

    Insert > Name > Define

    Name: NumLabels

    Refers to:

    =Sheet1!$A$1:INDEX(Sheet1!$A:$A,MATCH(9.99999999999999E+307,Sheet1!$A:$A)
    )

    Click Add

    Name: Values

    Refers to:

    =Sheet1!$B$1:INDEX(Sheet1!$B:$B,MATCH(9.99999999999999E+307,Sheet1!$A:$A)
    )

    Click Ok

    Then use the following array formula that needs to be confirmed with
    CONTROL+SHIFT+ENTER...

    =INDEX(NumLabels,ROWS(Values)-MATCH(TRUE,SUBTOTAL(9,OFFSET(Values,ROWS(Va
    lues)-1,0,-SMALL(ROW(Values)-MIN(ROW(Values))+1,ROW(Values)-MIN(ROW(Value
    s))+1)))>=C1,0)+1)

    ....where C1 contains your 'Sum Target Value'.

    Hope this helps!

    In article <5687cfd849b98@uwe>, "Sam via OfficeKB.com" <u4102@uwe>
    wrote:

    > Hi All,
    >
    > I am looking for a Formula that can process the following:
    >
    > The Sum Target Value is variable e.g.; 147
    > I have two columns of numerical values: Column “A” and Column “B.”
    > Column “A” Houses the Numerical Labels that I wish to have Returned when the
    > Sum Target Value is processed /reached - Subtract Sum Target Value as noted
    > below.
    >
    > To Subtract Sum Target Value:
    > Start from LAST non-zero numerical value in Column “B” and Subtract one Cell
    > value at a time (or Sum up the Column) until the Sum Target Value or nearest
    > possible Sum BELOW, the Sum Target Value is reached. In this instance, it is
    > 147. I wish to Sum the values in Column “B” to 147 per the above. The
    > summed values can be below BUT NOT over the Sum Target Value.
    >
    > Return the Numerical Value that is Offset ONE Cell to the LEFT (Column “A”)
    > and ONE Row Above LAST value Subtracted (in Column “B”) to reach Sum Target
    > Value. The Result – Numerical Label should come from Column “A.”
    >
    >
    > Col “A” Col “B”
    > 200 3
    > 205 1
    > 210 5
    > 215 11
    > 220 10
    > 225 15
    > 230 16
    > 235 10
    > 240 11
    > 245 29
    > 250 20
    > 255 27
    > 260 22
    > 265 34
    > 270 24
    > 275 36
    > 280 30
    > 285 25
    > 290 31
    > 295 26
    > 300 15
    > 305 18
    > 310 23
    > 315 17
    > 320 9
    > 325 11
    > 330 2
    > 335 9
    > 340 1
    > 0 0
    >
    > Reaching the Sum Target Value of 147 in Column “B” would go up to value 26,
    > Label 295 in Column “A”, totalling 131 which is below the Sum Target 147 but
    > including the value of 31 above it, would exceed the Sum Target Value of 147.
    > The required Result is returned from Column “A” Label 290 which is ONE Cell
    > to the LEFT (Column “A”) and ONE Row Above LAST value Subtracted (in Column
    > “B”).
    >
    > Thanks
    > Sam


  4. #4
    Ron Rosenfeld
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    On Fri, 28 Oct 2005 23:27:57 -0400, Ron Rosenfeld <[email protected]>
    wrote:

    >On Fri, 28 Oct 2005 21:01:37 GMT, "Sam via OfficeKB.com" <u4102@uwe> wrote:
    >
    >>Hi All,
    >>
    >>I am looking for a Formula that can process the following:
    >>
    >>The Sum Target Value is variable e.g.; 147
    >>I have two columns of numerical values: Column “A” and Column “B.”
    >>Column “A” Houses the Numerical Labels that I wish to have Returned when the
    >>Sum Target Value is processed /reached - Subtract Sum Target Value as noted
    >>below.
    >>
    >>To Subtract Sum Target Value:
    >>Start from LAST non-zero numerical value in Column “B” and Subtract one Cell
    >>value at a time (or Sum up the Column) until the Sum Target Value or nearest
    >>possible Sum BELOW, the Sum Target Value is reached. In this instance, it is
    >>147. I wish to Sum the values in Column “B” to 147 per the above. The
    >>summed values can be below BUT NOT over the Sum Target Value.
    >>
    >>Return the Numerical Value that is Offset ONE Cell to the LEFT (Column “A”)
    >>and ONE Row Above LAST value Subtracted (in Column “B”) to reach Sum Target
    >>Value. The Result – Numerical Label should come from Column “A.”
    >>
    >>
    >>Col “A” Col “B”
    >>200 3
    >>205 1
    >>210 5
    >>215 11
    >>220 10
    >>225 15
    >>230 16
    >>235 10
    >>240 11
    >>245 29
    >>250 20
    >>255 27
    >>260 22
    >>265 34
    >>270 24
    >>275 36
    >>280 30
    >>285 25
    >>290 31
    >>295 26
    >>300 15
    >>305 18
    >>310 23
    >>315 17
    >>320 9
    >>325 11
    >>330 2
    >>335 9
    >>340 1
    >>0 0
    >>
    >>Reaching the Sum Target Value of 147 in Column “B” would go up to value 26,
    >>Label 295 in Column “A”, totalling 131 which is below the Sum Target 147 but
    >>including the value of 31 above it, would exceed the Sum Target Value of 147.
    >>The required Result is returned from Column “A” Label 290 which is ONE Cell
    >>to the LEFT (Column “A”) and ONE Row Above LAST value Subtracted (in Column
    >>“B”).
    >>
    >>Thanks
    >>Sam

    >
    >Here's one way that'll get you the correct answer. It involves adding a third
    >column:
    >
    >C1: =SUM(B1:$B$30)
    >
    >Then copy/drag down to C30.
    >
    >The formula that will return the Label would then be:
    >
    >=INDEX(A1:A30,MATCH(target_value,C1:C30,-1)+(COUNTIF(C1:C30,target_value)=0))
    >
    >
    >--ron



    I misread your specifications. The correct formula would be:

    =INDEX(A1:A30,MATCH(D1,C1:C30,-1))


    --ron

  5. #5
    Sam via OfficeKB.com
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi Ron,

    Thank you. I really do appreciate you taking the time and effort to provide a
    workable solution to my often not so clear scenarios.

    Ron Rosenfeld wrote:
    >Here's one way that'll get you the correct answer. It involves adding a third column:


    >C1: =SUM(B1:$B$30)
    >Then copy/drag down to C30.
    >The formula that will return the Label would then be:
    >=INDEX(A1:A30,MATCH(target_value,C1:C30,-1)+(COUNTIF(C1:C30,target_value)=0))


    >--ron


    Your Formula gets me very close to my required Result. It provides the
    Numeric Label of the Summed Target Value; however, the required Result is the
    Numeric Label ONE Row above the Numeric Label of the Summed Target Value. I
    would have subtracted the value of one (1) from the Result returned by the
    Formula but unfortunately, in a few cases the Numeric Label above the Summed
    Target Value could be zero (0). Is there anyway of adding to your existing
    Formula to return the Numeric Label that is one Row above the Summed Target
    Value, excluding any Numeric Labels of zero (0) and thus returning what would
    be the next non-zero Numeric Label.

    Apologies for my over simplified example.

    Further assistance appreciated.

    Cheers
    Sam

    Ron Rosenfeld wrote:
    >Here's one way that'll get you the correct answer. It involves adding a third
    >column:
    >
    >C1: =SUM(B1:$B$30)
    >
    >Then copy/drag down to C30.
    >
    >The formula that will return the Label would then be:
    >
    >=INDEX(A1:A30,MATCH(target_value,C1:C30,-1)+(COUNTIF(C1:C30,target_value)=0))
    >
    >--ron



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...tions/200510/1

  6. #6
    Sam via OfficeKB.com
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi Domenic,

    Thank you. Your time and assistance is very much appreciated.

    Your Formula does provide exactly what I requested. Unfortunately, I over
    simplified the example: in a few cases the Numeric Label above the Summed
    Target Value could be zero (0). Is there anyway of adapting your existing
    Formula to exclude any Numeric Labels of zero (0) and thus return what would
    be the next non-zero Numeric Label.

    Apologies for my over simplified example.

    Further assistance appreciated.

    Cheers,
    Sam


    Domenic wrote:
    >Try the following...
    >
    >First, define dynamic ranges for Column A and Column B...
    >
    >Insert > Name > Define
    >
    >Name: NumLabels
    >
    >Refers to:
    >
    >=Sheet1!$A$1:INDEX(Sheet1!$A:$A,MATCH(9.99999999999999E+307,Sheet1!$A:$A)
    >)
    >
    >Click Add
    >
    >Name: Values
    >
    >Refers to:
    >
    >=Sheet1!$B$1:INDEX(Sheet1!$B:$B,MATCH(9.99999999999999E+307,Sheet1!$A:$A)
    >)
    >
    >Click Ok
    >
    >Then use the following array formula that needs to be confirmed with
    >CONTROL+SHIFT+ENTER...
    >
    >=INDEX(NumLabels,ROWS(Values)-MATCH(TRUE,SUBTOTAL(9,OFFSET(Values,ROWS(Va
    >lues)-1,0,-SMALL(ROW(Values)-MIN(ROW(Values))+1,ROW(Values)-MIN(ROW(Value
    >s))+1)))>=C1,0)+1)
    >
    >...where C1 contains your 'Sum Target Value'.
    >
    >Hope this helps!
    >
    >> Hi All,
    >>

    >[quoted text clipped - 58 lines]
    >> Thanks
    >> Sam



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...tions/200510/1

  7. #7
    Domenic
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi Sam!

    No problem, see if this is what you're looking for...

    D1:

    =ROWS(Values)-MATCH(TRUE,SUBTOTAL(9,OFFSET(Values,ROWS(Values)-1,0,-SMALL
    (ROW(Values)-MIN(ROW(Values))+1,ROW(Values)-MIN(ROW(Values))+1)))>=C1,0)+
    1

    ....confirmed with CONTROL+SHIFT+ENTER

    E1:

    =LOOKUP(2,1/(A1:INDEX(NumLabels,D1)>0),A1:INDEX(NumLabels,D1))

    Note that I've assumed that your data doesn't contain negative numbers.

    Hope this helps!

    In article <56932bf9b7374@uwe>, "Sam via OfficeKB.com" <u4102@uwe>
    wrote:

    > Hi Domenic,
    >
    > Thank you. Your time and assistance is very much appreciated.
    >
    > Your Formula does provide exactly what I requested. Unfortunately, I over
    > simplified the example: in a few cases the Numeric Label above the Summed
    > Target Value could be zero (0). Is there anyway of adapting your existing
    > Formula to exclude any Numeric Labels of zero (0) and thus return what would
    > be the next non-zero Numeric Label.
    >
    > Apologies for my over simplified example.
    >
    > Further assistance appreciated.
    >
    > Cheers,
    > Sam


  8. #8
    Sam via OfficeKB.com
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi Ron,

    >Ron Rosenfeld wrote:
    >I misread your specifications. The correct formula would be:


    >=INDEX(A1:A30,MATCH(D1,C1:C30,-1))


    Your Formula does now provide exactly what I requested. Unfortunately, I over
    simplified the example: in a few cases the Numeric Label above the Summed
    Target Value could be zero (0). Is there anyway of adapting your existing
    Formula to exclude any Numeric Labels of zero (0) and thus return what would
    be the next non-zero Numeric Label.

    Apologies for my over simplified example.

    Further assistance much appreciated.

    Cheers,
    Sam


    Ron Rosenfeld wrote:
    >>>Hi All,
    >>>

    >[quoted text clipped - 71 lines]
    >>
    >>--ron

    >
    >I misread your specifications. The correct formula would be:
    >
    >=INDEX(A1:A30,MATCH(D1,C1:C30,-1))
    >
    >--ron



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...tions/200510/1

  9. #9
    Sam via OfficeKB.com
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi Domenic,

    That's Great!

    Cheers,
    Sam

    Domenic wrote:
    >D1:
    >=ROWS(Values)-MATCH(TRUE,SUBTOTAL(9,OFFSET(Values,ROWS(Values)-1,0,-SMALL
    >(ROW(Values)-MIN(ROW(Values))+1,ROW(Values)-MIN(ROW(Values))+1)))>=C1,0)+1
    >...confirmed with CONTROL+SHIFT+ENTER


    >E1:
    >=LOOKUP(2,1/(A1:INDEX(NumLabels,D1)>0),A1:INDEX(NumLabels,D1))


    >Note that I've assumed that your data doesn't contain negative numbers.


    >Hope this helps!



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...tions/200510/1

  10. #10
    Domenic
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi Sam!

    After looking at this again, I've come up with another formula to
    replace the first one, which I believe is more efficient...

    D1:

    =ROWS(Values)-MATCH(TRUE,MMULT(--(LARGE(ROW(Values),ROW(Values)-MIN(ROW(V
    alues))+1)<=TRANSPOSE(ROW(Values))),Values)>=C1,0)+1

    ....confirmed with CONTROL+SHIFT+ENTER.

    Hope this helps!

    In article <[email protected]>,
    Domenic <[email protected]> wrote:

    > Hi Sam!
    >
    > No problem, see if this is what you're looking for...
    >
    > D1:
    >
    > =ROWS(Values)-MATCH(TRUE,SUBTOTAL(9,OFFSET(Values,ROWS(Values)-1,0,-SMALL
    > (ROW(Values)-MIN(ROW(Values))+1,ROW(Values)-MIN(ROW(Values))+1)))>=C1,0)+
    > 1
    >
    > ...confirmed with CONTROL+SHIFT+ENTER
    >
    > E1:
    >
    > =LOOKUP(2,1/(A1:INDEX(NumLabels,D1)>0),A1:INDEX(NumLabels,D1))
    >
    > Note that I've assumed that your data doesn't contain negative numbers.
    >
    > Hope this helps!


  11. #11
    Ron Rosenfeld
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    On Sat, 29 Oct 2005 19:40:14 GMT, "Sam via OfficeKB.com" <u4102@uwe> wrote:

    >Hi Ron,
    >
    >>Ron Rosenfeld wrote:
    >>I misread your specifications. The correct formula would be:

    >
    >>=INDEX(A1:A30,MATCH(D1,C1:C30,-1))

    >
    >Your Formula does now provide exactly what I requested. Unfortunately, I over
    >simplified the example: in a few cases the Numeric Label above the Summed
    >Target Value could be zero (0). Is there anyway of adapting your existing
    >Formula to exclude any Numeric Labels of zero (0) and thus return what would
    >be the next non-zero Numeric Label.
    >
    >Apologies for my over simplified example.
    >
    >Further assistance much appreciated.
    >
    >Cheers,
    >Sam


    In your expansion you do not indicate how many zeros might be present, but
    rather you ask to return the first non-zero label counting upwards.

    I decided it would be simpler to write (and perhaps subsequently modify) a UDF.

    The UDF accepts as arguments the Data table with numerical labels in the first
    column and your values in the second column. The second argument will be the
    Sum Target.

    It should give the result you specify no matter how many 0's are present.

    In addition, it will give a #NUM! error if the Sum Target cannot be reached.
    You can certainly add other error conditions.

    To enter this, <alt><F11> opens the VB Editor. Ensure your project is
    highlighted inthe project explorer window, then Insert/Module and paste the
    code below into the window that opens.

    To use this, enter a formula of the type:

    =label(A1:B30,D1)

    where A1:B30 is your table of Numerical Labels and Data, and D1 is the Sum
    Target.

    ===========================================
    Option Explicit

    Function Label(ByVal DataTable As Range, SumTargetValue As Range)
    Dim Dt As Variant
    Dim i As Long
    Dim s As Double

    Dt = DataTable

    For i = UBound(Dt) To 1 Step -1
    s = s + Dt(i, 2)
    If s >= SumTargetValue Then Exit For
    If i = 1 Then
    Label = CVErr(xlErrNum)
    Exit Function
    End If
    Next i

    Do Until Label <> 0
    Label = Dt(i, 1)
    i = i - 1
    Loop

    End Function
    =============================


    --ron

  12. #12
    Domenic
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Shorter...

    D1:

    =ROWS(Values)-MATCH(TRUE,MMULT(--(ROWS(Values)-ROW(Values)+1<=TRANSPOSE(R
    OW(Values))),Values)>=C1,0)+1

    ....confirmed with CONTROL+SHIFT+ENTER.

    Hope this helps!

    In article <[email protected]>,
    Domenic <[email protected]> wrote:

    > Hi Sam!
    >
    > After looking at this again, I've come up with another formula to
    > replace the first one, which I believe is more efficient...
    >
    > D1:
    >
    > =ROWS(Values)-MATCH(TRUE,MMULT(--(LARGE(ROW(Values),ROW(Values)-MIN(ROW(V
    > alues))+1)<=TRANSPOSE(ROW(Values))),Values)>=C1,0)+1
    >
    > ...confirmed with CONTROL+SHIFT+ENTER.
    >
    > Hope this helps!


  13. #13
    Domenic
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    For robustness...

    D1:

    =ROWS(Values)-MATCH(TRUE,MMULT(--(ROWS(Values)-(ROW(Values)-MIN(ROW(Value
    s))+1)+1<=TRANSPOSE(ROW(Values)-MIN(ROW(Values))+1)),Values)>=C1,0)+1

    ....confirmed with CONTROL+SHIFT+ENTER.

    Hope this helps!

    In article <[email protected]>,
    Domenic <[email protected]> wrote:

    > Shorter...
    >
    > D1:
    >
    > =ROWS(Values)-MATCH(TRUE,MMULT(--(ROWS(Values)-ROW(Values)+1<=TRANSPOSE(R
    > OW(Values))),Values)>=C1,0)+1
    >
    > ...confirmed with CONTROL+SHIFT+ENTER.
    >
    > Hope this helps!


  14. #14
    Sam via OfficeKB.com
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi Ron,

    Thank you for providing this neat Function. Unfortunately, it is returning
    #Value Error; any ideas?

    >To use this, enter a formula of the type:


    > =label(A1:B30,D1)


    >where A1:B30 is your table of Numerical Labels and Data, and D1 is the Sum Target.


    >===========================================

    Option Explicit

    Function Label(ByVal DataTable As Range, SumTargetValue As Range)
    Dim Dt As Variant
    Dim i As Long
    Dim s As Double

    Dt = DataTable

    For i = UBound(Dt) To 1 Step -1
    s = s + Dt(i, 2)
    If s >= SumTargetValue Then Exit For
    If i = 1 Then
    Label = CVErr(xlErrNum)
    Exit Function
    End If
    Next i

    Do Until Label <> 0
    Label = Dt(i, 1)
    i = i - 1
    Loop

    End Function
    =============================
    >--ron


    Cheers,
    Sam


    --
    Message posted via http://www.officekb.com

  15. #15
    Sam via OfficeKB.com
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi Domenic,

    Thank you so much for your endeavours.

    >For robustness...
    >D1:


    >=ROWS(Values)-MATCH(TRUE,MMULT(--(ROWS(Values)-(ROW(Values)-MIN(ROW(Value
    >s))+1)+1<=TRANSPOSE(ROW(Values)-MIN(ROW(Values))+1)),Values)>=C1,0)+1
    >...confirmed with CONTROL+SHIFT+ENTER.


    Cheers,
    Sam


    Domenic wrote:
    >For robustness...
    >
    >D1:
    >
    >=ROWS(Values)-MATCH(TRUE,MMULT(--(ROWS(Values)-(ROW(Values)-MIN(ROW(Value
    >s))+1)+1<=TRANSPOSE(ROW(Values)-MIN(ROW(Values))+1)),Values)>=C1,0)+1
    >
    >...confirmed with CONTROL+SHIFT+ENTER.
    >
    >Hope this helps!
    >
    >> Shorter...
    >>

    >[quoted text clipped - 6 lines]
    >>
    >> Hope this helps!



    --
    Message posted via http://www.officekb.com

  16. #16
    Sam via OfficeKB.com
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    Hi Ron,

    UDF is working Great!

    Found my problem: cell returning empty text.

    Thank you so much for your assistance.

    Cheers,
    Sam

    Sam wrote:
    >Hi Ron,
    >
    >Thank you for providing this neat Function. Unfortunately, it is returning
    >#Value Error; any ideas?
    >
    >>To use this, enter a formula of the type:

    >
    >> =label(A1:B30,D1)

    >
    >>where A1:B30 is your table of Numerical Labels and Data, and D1 is the Sum Target.

    >
    >>===========================================

    >Option Explicit
    >
    >Function Label(ByVal DataTable As Range, SumTargetValue As Range)
    >Dim Dt As Variant
    >Dim i As Long
    >Dim s As Double
    >
    >Dt = DataTable
    >
    >For i = UBound(Dt) To 1 Step -1
    > s = s + Dt(i, 2)
    > If s >= SumTargetValue Then Exit For
    > If i = 1 Then
    > Label = CVErr(xlErrNum)
    > Exit Function
    > End If
    >Next i
    >
    >Do Until Label <> 0
    > Label = Dt(i, 1)
    > i = i - 1
    >Loop
    >
    >End Function
    >=============================
    >>--ron

    >
    >Cheers,
    >Sam



    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.a...tions/200510/1

  17. #17
    Ron Rosenfeld
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    On Mon, 31 Oct 2005 03:21:48 GMT, "Sam via OfficeKB.com" <u4102@uwe> wrote:

    >Hi Ron,
    >
    >Thank you for providing this neat Function. Unfortunately, it is returning
    >#Value Error; any ideas?


    Possibly an entry in the Values column that is text and does not look like a
    number.

    If this is an issue, we can add some debugging code to try to sort it out.


    --ron

  18. #18
    Ron Rosenfeld
    Guest

    Re: Return Numerical Label for LAST value Subtracted to reach Sum Target Value

    On Mon, 31 Oct 2005 03:52:51 GMT, "Sam via OfficeKB.com" <u4102@uwe> wrote:

    >Hi Ron,
    >
    >UDF is working Great!
    >
    >Found my problem: cell returning empty text.
    >
    >Thank you so much for your assistance.
    >
    >Cheers,
    >Sam


    Glad it is working. Thanks for the feedback.
    --ron

+ 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