VB嵌套循环
Dim q As IntegerDim q1 As Integer
Dim q2 As Integer
Dim q3 As Integer
For q = 1 To MSFlexGrid3.Rows - 1
For q1 = 1 To MSFlexGrid3.Rows - 1
For q2 = 1 To MSFlexGrid3.Rows - 1
If MSFlexGrid3.TextMatrix(q, 0) = MSFlexGrid3.TextMatrix(1, 0) Then
MSFlexGrid2.TextMatrix(1, 0) = MSFlexGrid3.TextMatrix(1, 0)
If MSFlexGrid3.TextMatrix(q, 1) = MSFlexGrid3.TextMatrix(1, 1) Then
MSFlexGrid2.TextMatrix(1, 1) = MSFlexGrid3.TextMatrix(1, 1)
MSFlexGrid2.TextMatrix(1, 2) = Str(Val(MSFlexGrid3.TextMatrix(1, 2)) + Val(MSFlexGrid3.TextMatrix(q, 2)))
MSFlexGrid2.TextMatrix(1, 3) = Str(Val(MSFlexGrid3.TextMatrix(1, 3)) + Val(MSFlexGrid3.TextMatrix(q, 3)))
MSFlexGrid2.TextMatrix(1, 4) = Str(Val(MSFlexGrid3.TextMatrix(1, 4)) + Val(MSFlexGrid3.TextMatrix(q, 4))) + "+" + Str(Val(MSFlexGrid3.TextMatrix(1, 5)) + Val(MSFlexGrid3.TextMatrix(q, 5))) + "h"
Else
' MSFlexGrid2.TextMatrix(1 + q1, 1) = MSFlexGrid3.TextMatrix(q, 1)
' MSFlexGrid2.TextMatrix(1+q1, 2) = Str(Val(MSFlexGrid3.TextMatrix(q, 2)) + Val(MSFlexGrid3.TextMatrix(q3, 2)))
' MSFlexGrid2.TextMatrix(1+q1, 3) = Str(Val(MSFlexGrid3.TextMatrix(q, 3)) + Val(MSFlexGrid3.TextMatrix(q3, 3)))
' MSFlexGrid2.TextMatrix(1+q1, 4) = Str(Val(MSFlexGrid3.TextMatrix(q, 4)) + Val(MSFlexGrid3.TextMatrix(q3, 4))) + "+" + Str(Val(MSFlexGrid3.TextMatrix(q, 5)) + Val(MSFlexGrid3.TextMatrix(q3, 5))) + "h"
End If
End If
Next q2
Next q1
Next q
判断表格3(MSFlexGrid3)
若第一列内容相同
判断第二列
若第二列想同 则累计3 4 5列
若第二列不相同 则依旧判断第二列余下的行数 相同则累加 不相同则另起一行
若第一列不相同 则另起一行 又重新开始判断
程序循环比较差,求大神指教!!!