Charles Chickering
12/19/2006 10:16:00 PM
Oops forgot to move rFirstSum to the next group of numbers.
Sub SumStuff()
Dim rLastCell As Range
Dim rFirstSum As Range
Dim rLastSum As Range
Set rLastCell = Range("I" & Rows.Count).End(xlUp)
Set rFirstSum = Range("I8")
Do
If rFirstSum.Offset(1) = "" Then
rFirstSum.Offset(, 1).Formula = _
"=Sum(" & rFirstSum.Address & ")"
Set rFirstSum = rFirstSum.End(xlDown)
Else
Set rLastSum = rFirstSum.End(xlDown)
rLastSum.Offset(, 1).Formula = _
"=Sum(" & Range(rFirstSum, rLastSum).Address & ")"
Set rFirstSum = rLastSum.End(xlDown)
End If
Loop Until rFirstSum.Row >= rLastCell.Row Or _
rLastSum.Row >= rLastCell.Row
End Sub
Sry 'bout that.
--
Charles Chickering
"A good example is twice the value of good advice."
"Charles Chickering" wrote:
> Sub SumStuff()
> Dim rLastCell As Range
> Dim rFirstSum As Range
> Dim rLastSum As Range
> Set rLastCell = Range("I" & Rows.Count).End(xlUp)
> Set rFirstSum = Range("I8")
> Do
> If rFirstSum.Offset(1) = "" Then
> rFirstSum.Offset(, 1).Formula = _
> "=Sum(" & rFirstSum.Address & ")"
> Else
> Set rLastSum = rFirstSum.End(xlDown)
> rLastSum.Offset(, 1).Formula = _
> "=Sum(" & Range(rFirstSum, rLastSum).Address & ")"
> End If
> Loop Until rFirstSum.Row >= rLastCell.Row Or _
> rLastSum.Row >= rLastCell.Row
> End Sub
>
> Try that.
> --
> Charles Chickering
>
> "A good example is twice the value of good advice."
>
>
> "blazzzercat" wrote:
>
> > I need a macro that will SUM the cells in rows that vary in the number of
> > rows and put the total in the column next to the last number before a blank
> > row. It will then go down the column until it finds another row with a number
> > in it and SUM those rows until the next blank row, loop until no more rows
> > with numbers are found. The cells always start in I-8. I need the totals in
> > column J.
> >
> > Thanks so much in advance.
> >
> >