View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Kris Taylor Kris Taylor is offline
external usenet poster
 
Posts: 18
Default Average If Macro

Ron Rosenfeld wrote in message . ..
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


Ron,

Thanks for your help thus far. For some reason however, the macro
seems to be giving me a Type Mismatch error. On the first page, it
gives me 47 averages, then stops, the second page gives me around 10
and the third page gives me nothing.

I went through it and made sure there were no spaces, formatted so
that everything was a number and I still have the same problem...

Any suggestions? Is my spreadsheet too big?

Let me know!

Thanks again for all of your help up to now!

Kris Taylor