VBA Code to Calculate Average of Filtered Data in Excel

This code calculates the average of the visible cells in a filtered range.

VBA Code:

Sub CalculateAverageFilteredData()
    Dim visibleRange As Range
    
    Set visibleRange = ActiveSheet.AutoFilter.Range.SpecialCells(xlCellTypeVisible)
    MsgBox "Average: " & Application.WorksheetFunction.Average(visibleRange)
End Sub
Join Our Telegram Group techguruplus telegram group Join Our WhatsApp Group techguruplus whatsapp group

Leave a Comment