View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Summing Contiguous Values in a Column?

I'd use a macro.

If that's ok:

Option Explicit
Sub testme()
Dim myRng As Range
Dim myNumbers As Range
Dim myArea As Range
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

Set myNumbers = Nothing
On Error Resume Next
Set myNumbers = myRng.Cells.SpecialCells(xlCellTypeConstants, xlNumbers)
On Error GoTo 0

If myNumbers Is Nothing Then
MsgBox "No number constants in column A!"
Exit Sub
End If

For Each myArea In myNumbers.Areas
With myArea
.Resize(1, 1).Offset(.Rows.Count, 1).Formula _
= "=sum(" & .Address(0, 0) & ")"
End With
Next myArea

End Sub



Select the range to fix first and run it.

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

Confused_in_Houston wrote:

I have groupings of data in column A. Each group is obviously continguous.
The data grouping are separated by a single blank cell in the column. I
would like to sum the values in each group.

What I have:

A
1000
500
300
200

1000
400
100

1000
1000

What I'd like:

A B
1000
500
300
200
2000
1000
400
100
1500
1000
1000
2000

thanks!


--

Dave Peterson