View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Count every group of numbers whose sum is zero & put number next to each number

Here's a simple sub that will do it.

Sub AAA()
Dim R As Range
Dim T As Long
Dim N As Long
Dim C As Long
Set R = Range("A1")
Do Until R.Value = vbNullString
T = T + R.Value
N = N + 1
If T = 0 Then
C = C + 1
R(1, 2).Offset(-1 * N + 1).Resize(N).Value = C
N = 0
End If
Set R = R(2, 1)
Loop
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Mon, 16 Mar 2009 19:24:19 -0700 (PDT), al
wrote:

I have the following numbers in column A
1
2
3
-2
-4
5
5
-10
3
3
-6

I need in column B next to each number - the number telling me to
which
group of sum zero it belows(by selecting first cell next to column A
up to last cell - (B1:B11) i.e

1,2,3,-2,-4 would each have number 1 next to each of them in column B
(first group of sum zero)

5,5,-10 would each have number 2 next each of them in column B (second
group of sum zero)

3,3,-6 would each have number 3 next to each of them in column B
(third group of sun zero)


Need a macro which would work in any range of numbers in any column
( not necessarily column A i.e if numbers are in column D - count
would be in column E next to the number

Pls help thxs