You are using MAX property incorrectly. The code you are using would check only 2 cells. This is how it should be used-
![]()
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(Range(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
Bookmarks