Excel VBA, sum of elements in a matrix
Argile92
Posted messages
10
Status
Member
-
Chricky_80 -
Chricky_80 -
Hello,
I have a problem that I think is very simple to resolve for people who know the command to use.
So, I coded in a macro a matrix of the form "matrice(1 to 10, 1 to 5)" and I would like to sum the elements "matrice(1 to 10, 1)" i.e. the 10 elements found in the 1st column.
Is there a command other than
WorksheetFunction.Sum(matrice(1,1), matrice(2,1) ... etc...) ?
Thanks for your help
Configuration: Windows XP Internet Explorer 6.0
I have a problem that I think is very simple to resolve for people who know the command to use.
So, I coded in a macro a matrix of the form "matrice(1 to 10, 1 to 5)" and I would like to sum the elements "matrice(1 to 10, 1)" i.e. the 10 elements found in the 1st column.
Is there a command other than
WorksheetFunction.Sum(matrice(1,1), matrice(2,1) ... etc...) ?
Thanks for your help
Configuration: Windows XP Internet Explorer 6.0
1 answer
-
I don’t know if that answers your question but try:
Sub test()
StartLine = 1 'Line of your starting cell
StartColumn = 2 'Column of your starting cell
For Line = StartLine To StartLine + 10 'Loop of 10 occurrences
For Column = StartColumn To StartColumn + 5 'Loop of 5 occurrences
Sum = Cells(Line, Column) + Sum 'Old sum + new cell
Next
Next
'to visualize your result
mess = "Sum is equal to " & Sum
MsgBox (mess)
End Sub
See you later
Chricky_80