Here's the function. However, there's no way we can get the formula to auto-refresh when a column is hidden or unhidden. You would have to recalculate the sheet by pressing Shift + F9 or from the 'Formulas' tab.
Function SpecialAverage(rng1 As Range, x As Long)
Application.Volatile
Dim cll As Range
Dim dblSum As Double
Dim lngCnt As Long
For Each cll In rng1.Cells
If lngCnt = x Then Exit For
If Not cll.EntireColumn.Hidden Then
dblSum = dblSum + cll.Value
lngCnt = lngCnt + 1
End If
Next cll
SpecialAverage = dblSum / lngCnt
End Function
Bookmarks