Summing visible column values but not hidden column values

B

BW

I need to write a SUM function that will add up the numbers in several
columns of data (for example, A4:S4), but I only want it to add those columns
that are visible, not those that are hidden. Is there any way to have Excel
add only the numbers in the visible columns, not in any hidden columns?
Thanks.
 
N

Nikki

If you put this code into the editor you can then use the function
sum_visible_cells
instead of =sum(a4:s4) you type =sum_visible_cells(a4:s4)

Function Sum_Visible_Cells(Cells_To_Sum As Object)
Application.Volatile
For Each cell In Cells_To_Sum
If cell.Rows.Hidden = False Then
If cell.Columns.Hidden = False Then
total = total + cell.Value
End If
End If
Next
Sum_Visible_Cells = total
End Function
 
Top