Returns an aggregate function (sum, average, and so on) for a given range.
Syntax
val# = [form!]VSFlexGrid.Aggregate(Aggregate As SubtotalSettings, Row1 As Long, Col1 As Long, Row2 As Long, Col2 As Long)
Remarks
This property is used to quickly calculate totals, averages and other aggregates over a range of cells.
The parameters for the Aggregate property are described below:
Aggregate As SubtotalSettings
This parameter defines the type of aggregate function to use. Valid settings for this parameter are:
Constant |
Value |
Description |
flexSTNone |
0 |
Outline only, no aggregate values |
flexSTClear |
1 |
Clear all subtotals |
flexSTSum |
2 |
Sum |
flexSTPercent |
3 |
Percent of total sum |
flexSTCount |
4 |
Row count |
flexSTAverage |
5 |
Average |
flexSTMax |
6 |
Maximum |
flexSTMin |
7 |
Minimum |
flexSTStd |
8 |
Standard deviation |
flexSTVar |
9 |
Variance |
flexSTStdPop |
10 |
Standard Deviation Population |
flexSTVarPop |
11 |
Variance Population |
Row1 As Long, Col1 As Long, Row2 As Long, Col2 As Long
These parameters define the range over which the aggregate is to be calculated. If you set Row1 and Row2 to -1, all selected rows are used (the selection does not have to continuous).
For example,
Debug.Print fg.Aggregate(flexSTCount, fg.FixedRows, 2, fg.Rows - 1, 2)
Debug.Print fg.Aggregate(flexSTSum, fg.FixedRows, 2, fg.Rows - 1, 2)
Debug.Print fg.Aggregate(flexSTSum, -1, 2, -1, 2)
The first statement would print the number of numeric entries in column 2, and the second their sum.
The last statement would print the sum of all numeric entries in column 2 on currently selected rows. This type of calculation is especially useful when the SelectionMode property is set to flexSelectionListBox (3).
Data Type
Double