View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam via OfficeKB.com Sam via OfficeKB.com is offline
external usenet poster
 
Posts: 247
Default Count & Sum Consecutive (2x) appearance of Specific Numeric Values

Hi Tom,

Apologies, no need for my amendment to

ElseIf ar.Count = 5 Then
cnt1 = cnt1 + 2


I should have used your first version of the code and not the version headed
up "this matches your results".

Cheers,
Sam

Tom Ogilvy wrote:
Sub CountData()

Dim rng As Range, rng1 As Range
Dim cnt As Range, cell As Range
Dim cell1 As Range, cnt1 As Long
Set rng = Range("Data")
Set rng1 = Range(Cells(2, 1), Cells(2, 1).End(xlDown))
For Each cell In rng1
Set rng2 = Nothing
For Each cell1 In rng
If cell1 = cell Then
If rng2 Is Nothing Then
Set rng2 = Cells(cell1.Row, 1)
Else
Set rng2 = Union(rng2, Cells(cell1.Row, 1))
End If
End If
Next
cnt1 = 0
For Each ar In rng2.Areas
If ar.Count = 2 Then
cnt1 = cnt1 + 1
End If
Next
cell.Offset(0, 1).Value = cnt1
Next
End Sub


Produces results matching yours except for 129.


29 is correct per your VBA code. My count was incorrect.

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