I'm trying to skip the blank cells from a range so that it does not alter my simple moving average. So I try to start from a range, "copy/paste" the non blank values within a new range called oRng so that I can use the new range to calculate my SMA.
I got a error 5 saying "Argument or procedure call incorrect" on this line
Set oRng = Application.Union(oRng, cell)
Here is my full code:
Function SMA(rng As Range, N As Integer)
Dim oRng As Range
Dim cell As Range
On Error GoTo ErrHandler
For Each cell In rng
If not IsEmpty(cell) = True Then
Set oRng = Application.Union(oRng, cell)
Next cell
SMA = Application.Average(oRng.Resize(N, 1))
ErrHandler:
Debug.Print Err.Description
End Function
