EXCEL VBA累加

K2:T3为区域1

以下代码及注释是实现数字的累计,请参考:
Sub n()
Dim i, k As Integer '定义变量i,k为整型变量
For i = 1 To 100 'i从1到100循环
k = k + 1 'k每次累计1
Next '继续循环
MsgBox k '显示k的最终值
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-01-24
Sub s()
    ct = 2
    Set d = CreateObject("scripting.dictionary")
    For i = 11 To 20
    d(Cells(2, i).Text) = Val(Cells(3, i))
    Next
    c = 0
    Do While c < ct
        t = 0
        For Each k In d.keys
            If d(k) > t Then t = d(k)
        Next
        For Each k In d.keys
            If d(k) = t Then
                For i = 1 To 3 Step 2
                For j = 5 To 9
                    If Cells(i, j).Text = k Then
                        Cells(i + 1, j) = Cells(i + 1, j) + 1
                        d.Remove (k)
                        c = c + 1
                    End If
                Next
                Next
            End If
        Next
    Loop
    d.RemoveAll
    For i = 11 To 20
    d(Cells(8, i).Text) = Val(Cells(9, i))
    Next
    c = 0
    Do While c < ct
        t = 0
        For Each k In d.keys
            If d(k) > t Then t = d(k)
        Next
        For Each k In d.keys
            If d(k) = t Then
                For i = 7 To 9 Step 2
                For j = 5 To 9
                    If Cells(i, j).Text = k Then
                        Cells(i + 1, j) = Cells(i + 1, j) + 1
                        d.Remove (k)
                        c = c + 1
                    End If
                Next
                Next
            End If
        Next
    Loop
End Sub

本回答被提问者采纳
相似回答