I use the following code that takes care of this (& works better for me as I cannot always use AutoFilters in my spreadsheets):
Function SumVisibleCells(CellsToSum As Object)
'sums only visible cells, ignoring cells in hidden rows or columns
Dim cell As Variant
Dim total As Single 'I use Single as my values contain decimals
Application.Volatile
For Each cell In CellsToSum
If cell.Rows.Hidden = False Then
If cell.Columns.Hidden = False Then
total = total + cell.Value
End If
End If
Next
SumVisibleCells = total
End Function
To check type the following data into a blank spreadsheet:
A1 = 1 B1 = 2
A2 = 2 B2 = 4
A3 = 3 B3 = 6
A4 = 4 B4 = 8
A5 = 5 B5 = 10
Hide row 3
In A6 type the following formula:
=SUM(A1:B5)
result should be 45
In B6 type the following formula:
=sumvisiblecells(A1:B5)
result should be 36
Remember, user must press F9 after spreadsheet changes to recalculate