[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 877
  • Last Modified:

calculating a column value in a FlexGrid.

Hi all. Does anyone know how to calculate a value from a colum in a FlexGrid. i know i can use SQL sum function to do this when retrieving a recordset. I would like however to calculate them from a column.
ex.
column values:
10
20

result is 30. Help is greatly appreciated. Thanks.
0
Marine
Asked:
Marine
  • 2
1 Solution
 
mcriderCommented:
You can use this SumCol function to sum columns. For example if you want to sum column 1 rows 2-5 you can do this:

x=SumCol(msflexgrid1,1,2,5)

Cheers!


THE CODE:

Function SumCol(GridName As Object, Column As Long, _
        Optional StartRow As Variant, Optional EndRow As Variant) As Variant
    Dim lStart As Long
    Dim lEnd As Long
    Dim iVal As Long
    Dim lTotal As Variant
    On Error Resume Next
    lTotal = 0
    With GridName
        lStart = 0: If IsMissing(StartRow) = False Then lStart = CLng(StartRow)
        lEnd = .Rows: If IsMissing(EndRow) = False Then lEnd = CLng(EndRow)
        For iVal = lStart To lEnd
            lTotal = lTotal + CCur(.TextMatrix(iVal, Column))
        Next iVal
    End With
    SumCol = lTotal
End Function
0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now