Good day,

I am attempting to build a countif to count each cell, in range of cells in the same row (Myrange), that is the maximum for rows i-n to i+n in each cell's respective column. Currently the function below returns a 0 value in all application uses for any given row range and an n. Any assistance will be appreciated.



Function CountIfMax(Myrange As Range, n As Integer) As Double

Dim i As Integer
Dim cell As Range

i = ActiveCell.Row

For Each cell In Myrange

    Max = Application.Max(Cells(i - n, cell.Column), Cells(i + n, cell.Column))
    actcell = Cells(i, cell.Column)

    If actcell = Max Then
        CountIfMax = CountIfMax + 1
    End If

    
Next cell

End Function