Summing the numbers, resulting at least 10?

slowokan

New Member
Joined
Dec 6, 2011
Messages
19
Hi there.

I have one problem about summing the numbers in 9 cells in a row and doing this for the following rows as well.

The thing I need is like this;

2 3 6 5 2 7 2 4 9

First, change the number to 1, if a cell is 6 and the sum of the cells before that cells is greater than 4. In this case, we have 6 in the 3rd cell and also the sum of the cells before 3rd cell is greater (3+2=5) than 4, so 6 will be replaced by 1 and the new row is gonna look like this;

2 3 1 5 2 7 2 4 9 (The row doesn't need to be copied into another row. I wrote this just to give an idea).

Secondly, sum the numbers and if it results > 10, then stop summing and write the result next to the last cell. For this example, we get at least 10, at 4th cell, which results 2 + 3 + 1 + 5 = 11. And write the result next to the last cell(Number 9 here). And also, delete the unused cells after.

And the new row becomes;

2 3 1 5 ____________ 11 (This is the result)

And repeat this for many rows until the Activecell sees empty cell.

I wrote a function, it doesn't give an error but I don't get the exact thing I want. Thanks in advance...

Sub ToplamDeneme()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
'<o:p></o:p>
' ToplamDeneme Macro<o:p></o:p>
'<o:p></o:p>
<o:p></o:p>
'<o:p></o:p>
Do<o:p></o:p>
<o:p></o:p>
Dim Cell As Range<o:p></o:p>
Set Cell = ActiveCell.Offset(, 1)<o:p></o:p>
Do While Not IsEmpty(Cell)<o:p></o:p>
If Application.Sum(Range(Cells(ActiveCell.Row, 1), Cell)) >= 10 Then<o:p></o:p>
If Cell.Value = 6 Then<o:p></o:p>
If Application.Sum(Range(Cells(ActiveCell.Row, 1), Cell.Offset(, -1))) > 4 Then<o:p></o:p>
Cell.Value = 1<o:p></o:p>
Cells(ActiveCell.Row, 10).Value = Application.Sum(Range(Cells(ActiveCell.Row, 1), Cell))<o:p></o:p>
Range(Cell.Offset(, 1), Cells(ActiveCell.Row, 9)).Select<o:p></o:p>
Selection.ClearContents<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
Set Cell = Cell.Offset(, 1)<o:p></o:p>
<o:p></o:p>
Loop<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(1, 0).Select<o:p></o:p>
<o:p></o:p>
Loop Until IsEmpty(ActiveCell)<o:p></o:p>
<o:p></o:p>
End Sub
 
Ah good point!

Try:
Code:
Sub example()

Dim lrw As Long
Dim cl As Range
Dim lsum As Double

For lrw = 1 To Range("A1").End(xlDown).Row 'loop through rows
    lsum = 0
    For Each cl In Cells(lrw, 1).Resize(1, 9)
        If cl = 6 Then
            If cl.Column <> 1 Then
                If Application.Sum(cl.Offset(0, 1 - cl.Column).Resize(1, cl.Column - 1)) > 4 Then
                    cl = 1
                End If
            End If
        End If
        lsum = lsum + cl
        If lsum >= 10 Then
            Cells(lrw, 1).Offset(0, 9) = lsum
            If cl.Column <> 9 Then
                cl.Offset(0, 1).Resize(1, 9 - cl.Column).ClearContents
            End If
            Exit For
        End If
    Next cl
Next lrw

End Sub

Note I assume you want a Total shown when >=10 not only >10.
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top