VBA很容易计划和奋斗

时间:2017-12-05 16:54:44

标签: vba

因此我出于某种原因而出现错误"接下来没有#34; 这是代码:

Sub test()
Dim y As Integer
y = 0

For i = 1 To 7
    For j = 1 To 7
        If Cells(i, 1) = Cells(j, 1) Then
            y = y + 1

    Next j

        Cells(i, 2).Value = y
        y = 0
Next i


End Sub

1 个答案:

答案 0 :(得分:1)

问题不是来自For ... To ... Next,而是来自If条件,即您忘记使用End If指令关闭。

Sub test()
    Dim y As Integer
    y = 0

    For i = 1 To 7
        For j = 1 To 7
            If Cells(i, 1) = Cells(j, 1) Then
                y = y + 1
            End If 'You forgot to end the condition
        Next j

        Cells(i, 2).Value = y
        y = 0
    Next i
End Sub