Excel在单元格中显示无限重复的值

Cal*_*ins 2 excel formatting vba excel-vba

我的Excel电子表格包含一列,其行可以包含值0,12.我的VBA代码对0s 的数量(特别是非1或的值2)求和,并将计数放入下面的单元格中.这似乎运行正常,因为最后单元格的值等于0应该的s 数,但数字显示如下(应该只是9):

无限数字

数字无限重复.

我的VBA代码:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("F22")) Is Nothing And Not Intersect(Target, Range("F4:F21")) Is Nothing Then
        Dim count As Integer
        For i = 4 To 21:
            If Not Cells(i, "F").Value = 1 And Not Cells(i, "F").Value = 2 Then
                count = count + 1
            End If
        Next i
        Cells(22, "F").Value = count
    End If
End Sub
Run Code Online (Sandbox Code Playgroud)

这是VBA问题还是我的文档格式不正确?

pnu*_*uts 5

我认为您已使用Horizo​​ntal:alignment格式化单元格Fill.