Summing visible column values but not hidden column values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top