'定义一个多一行多一列的数组,就象表格,把汇总结果放在后头
Private Sub Command1_Click()
Dim Source
Source = "4,35,43,56;43,65,34,26;34,54,35,56"
'Source = InputBox("行以分号分隔,列以逗号分隔"): If Source = Empty Then Exit Sub'可以改为对话框输入
Dim Table(1 To 4, 1 To 5)
Dim arLine, arCol
arLine = Split(Source, ";") '分隔
字符串行
Dim i As Integer, j As Integer
'数据填充到表格
For i = 1 To 3 '三行
arCol = Split(arLine(i - 1), ",") '分隔每行字符串的列
For j = 1 To 4 '四列
Table(i, j) = Val(arCol(j - 1))
Next
Next
Dim sumLow, sumCol
'汇总表格行列,把结果加入表格最后行列
For i = 1 To 3 '三行
For j = 1 To 4 '四列
Table(i, 5) = Table(i, 5) + Table(i, j) '累加同行的数到最后一列
Table(4, j) = Table(4, j) + Table(i, j) '累加同列的数到最后一行
Next
Next
'显示
For i = 1 To UBound(Table, 1) '四行
For j = 1 To UBound(Table, 2) '五列
Print Table(i, j), ;
Next
Print
Next
End Sub