santiperez
New Member
- Joined
- Jan 8, 2009
- Messages
- 3
Hi,
I've been working with this formula and, although it gives the correct result, it is very slow.
When I use it many times in the same workbook it losses functionality.
The formula calculates monthly averages.
Date and numbers must be arranged in columns (the date and the correspondient number must be in the same row) .
It compares dates in the column with an specified month and makes the average of the correspondient data.
Is there any way of reducing steps or changing something so as to make it go faster?
I would appreciate any comment.
Thanks.
I've been working with this formula and, although it gives the correct result, it is very slow.
When I use it many times in the same workbook it losses functionality.
The formula calculates monthly averages.
Date and numbers must be arranged in columns (the date and the correspondient number must be in the same row) .
It compares dates in the column with an specified month and makes the average of the correspondient data.
Is there any way of reducing steps or changing something so as to make it go faster?
I would appreciate any comment.
Thanks.
Code:
Function PMES(R As Range, F As Range, D As Date) As Double
Dim n As Integer
Dim b As Integer
Dim sump As Double
Dim mes As Date
mes = DateSerial(Year(D), Month(D), 1)
n = 0
sump = 0
b = R.Column
For Each x In F
If DateSerial(Year(x), Month(x), 1) = mes Then
sump = sump + Cells(x.Row, b)
n = n + 1
End If
Next x
PMES = sump / n
End Function