View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Average If Macro

Noted some typos and a little cleanup:

=================================
Option Explicit
Sub AvgGT15()
Dim AOI As Range
Dim StoreResult As Range
Dim c As Range
Dim i As Long
Dim Result()

Set StoreResult = [M1]
Set AOI = [D1:D5000]
[M1:M5000].ClearContents

i = 0
ReDim Preserve Result(i)

For Each c In AOI
If c.Value < 15 Then
If Result(0) = 15 Then
StoreResult.Value = Application.WorksheetFunction.Average(Result())
Set StoreResult = StoreResult.Offset(1, 0)
End If
i = 0
Result(0) = 0
Else
ReDim Preserve Result(i)
Result(i) = c.Value
i = i + 1
End If
Next c

If Result(0) = 15 Then StoreResult.Value = _
Application.WorksheetFunction.Average(Result())

End Sub
========================

--ron