Search code examples
excelexcel-formulaaggregatesubtotal

Sum only visible cells in one ROW (not column)?


I have a row and I want to sum only visible cells, i know if it's a column I can use subtotal (109,range), but this one doesn't seem to work for cells in one row. Anyone knows how to sum only visible cells in a row?

Please click here for picture

enter image description here


Solution

  • If a VBA solution is okay, this will work:

    Function sumVisible(rng As Range) As Double
    Dim cel As Range
    For Each cel In rng
        If cel.EntireColumn.Hidden = False Then
            sumVisible = sumVisible + cel.Value
        End If
    Next cel
    End Function
    

    Pretty straightforward - just checks if a cell in your range has a hidden column, if it's visible, sum it.

    =sumVisible(D2:M2) is how you'd use it.