Hi Eva,
I use this sub to create an array constant, which I can use in a Sum
formula on the worksheet.
Suppose the numbers you are summing are named "myRange" in Excel. To
sum them all you would use
=Sum (myRange)
in a worksheet cell. If you run the sub below (say from a worksheet
form button) you can sum the visible rows using the worksheet formula
= Sum(if(ShownRows,myRange,0))
and enter it as an array formula (Ctrl+Shift+Enter)
This is much faster than creating a Range object consisting of the
visible rows and summing that range. It also separates the hiding task
from the summing task.
regards
Paul
Public Sub Create_Filtered_Array()
'Creates an array of true/false for a row not hidden/hidden
'array is named to be used by worksheet
'This array is used in worksheet functions to apply them to filtered
data only
Dim rgRow As Range
Dim FilterArray() As Boolean
Dim rownumber As Integer
Dim k As Integer
Dim Test_1 As Variant, L_Cert As Variant, Grade As Variant, Attendence
As Variant, Improvement As Variant
Application.ScreenUpdating = False
With Range("myRange") 'All cells in this range should be
occupied
rownumber = .Rows.Count
ReDim FilterArray(1 To rownumber, 1 To 1)
For k = 1 To rownumber
FilterArray(k, 1) = Not .Rows(k).EntireRow.Hidden
Next k
End With
Names.Add Name:="ShownRows", RefersTo:=FilterArray
'Creates a named array constant, consisting of a column of Booleans
End Sub