对于循环不会在工作表中运行

时间:2017-01-01 10:29:44

标签: excel vba

在以下代码中,for循环不会运行。 msgbox显示我没有激活一次。范围确实清除,因此A10:A300被清除。但在那之后,在循环中,没有任何事情发生。

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Target.Worksheet.Range("B7")) Is Nothing Then
    Target.Worksheet.Range("A10", "A300").Clear
    Dim i As Integer
    Dim j As Integer
    j = 10
    For i = 4 To 10
        MsgBox i
        If ThisWorkbook.Sheets(1).Cells(i, 2) = Target Then
            Target.Worksheet.Cells(j, 1) = ThisWorkbook.Sheets(1).Cells(i, 3)
            j = j + 1
            MsgBox (ThisWorkbook.Sheets(1).Cells(i, 4))
        End If
    Next i
End If
End Sub

0 个答案:

没有答案