Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA SUM only if Visible

Status
Not open for further replies.

Randy11

Technical User
Oct 4, 2002
175
CA
Have a worksheet that can have hideden columns in it. Would like to be able to sum only the visible cells in a row. Info below:

With VBA would like to:
~Sum Values in Range C4:AF4
~Place totals in Cell AH4

~Any one or more of the columns C to AF could be hidden.
~Sum in AH needs to reflect only Values of the visible cells.

Range("AJ4").Value = Application.Sum(Range("C4:AG4"))
-This works to get total. How can I add the part that only sums if not hidden? or Hidden - False?
 
Solved: Just found a great solution to this, so far works excellent. Pick this up from Excel Forum - Forum Guru....
This is an easy solution.
Function SUMVIS(rng)
Dim CellSum As Long
Dim Cell As Range
Application.Volatile
CellSum = 0
Set rng = Intersect(rng.Parent.UsedRange, rng)
For Each Cell In rng
If IsNumeric(Cell) Then
If Not Cell.EntireRow.Hidden And _
Not Cell.EntireColumn.Hidden Then _
CellSum = CellSum + Cell
End If
Next Cell
SUMVIS = CellSum
End Function

'Enter : =SUMVIS(..your columns...)
 
hi,

No VBA required!!!

Use the SUBTOTAL() Function 109 Function Num.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top