[RESOLVED] how to get the sum of all values of rows in a certain column?
:confused:
_______________
lcolumn 1l
l 3 l
l 4 l
l 5 l
(textbox)
sum
how to get the sum?????
Re: how to get the sum of all values of rows in a certain column?
Welcome to the forums... :wave:
What are you referring with the word 'column' ? An array? ListView column ? FlexGrid column ?
Re: how to get the sum of all values of rows in a certain column?
Re: how to get the sum of all values of rows in a certain column?
Something like this might work:
VB Code:
Dim index As Integer
Dim mySum As Double
Dim columnToSum as integer
mySum = 0
columnToSum = 1
For index = 1 To (MSFlexGrid1.Rows - 1)
mySum = mySum + Val(MSFlexGrid1.TextMatrix(index, columnToSum))
Next index
MsgBox mySum
Make the index variable a long if you have more than 32767 rows in your grid.
I started at index = 1 as I assumed you have a header row, if you don't and just have data without a header, change "index = 1 to" to "index = 0 to".
I'm not sure if there is a way to run a sub-sql-query directly on the underlying RecordSet but if not then the above hopefully works for you.
You might want to add some validation in case of NULL values.