我在VBA遇到了一个特殊的怪癖,我不确定永久修复 . 触发MsgBox时,只会将值添加到我的字典中 . 我期待12345被添加到我的字典中 . 不过我是下面的第一个例子,但事实并非如此 .

For i = 2 To lastrow
    If (Not today.exists(.Cells(i, headers.Item("SL_ID")).Value) And _
       .Cells(i, headers.Item("Assigned Date")).Value >= Date - minusDays And _
       Len(.Cells(i, headers.Item("Assigned Status")).Value) > 3 And _
       InStr(LCase(.Cells(i, headers.Item("Assigned Status")).Value), "started") = 0) Then
           today.Add Key:=.Cells(i, headers.Item("SL_ID")).Value, _
            Item:=Array(.Cells(i, headers.Item("Assigned Status")).Value, _
                        .Cells(i, headers.Item("Completion Date")).Value, _
                        .Cells(i, headers.Item("On Hold Comments")).Value, _
                        "-", "-", "-", "-", "Rework", source)
    End If
Next i

但是以下带有MsgBox的代码确实按预期工作,并且12345被添加到我的字典中 .

For i = 2 To lastrow
    If (.Cells(i, headers.Item("SL_ID")).Value = "12345") Then
        MsgBox ("Wow, it's 12345")
    End If

    If (Not today.exists(.Cells(i, headers.Item("SL_ID")).Value) And _
       .Cells(i, headers.Item("Assigned Date")).Value >= Date - minusDays And _
        Len(.Cells(i, headers.Item("Assigned Status")).Value) > 3 And _
        InStr(LCase(.Cells(i, headers.Item("Assigned Status")).Value), "started") = 0) Then
                today.Add Key:=.Cells(i, headers.Item("SL_ID")).Value, Item:=Array(.Cells(i, headers.Item("Assigned Status")).Value, .Cells(i, headers.Item("Completion Date")).Value, .Cells(i, headers.Item("On Hold Comments")).Value, "-", "-", "-", "-", "Rework", source)
    End If
Next i

有没有人知道为什么会这样?打开MsgBox的暂停是否允许Excel“赶上”并正确添加?这是一个已知的问题?

任何帮助表示赞赏 . 显然我的解决方案不是永久性的解决方案,我很想知道为什么会发生这种奇怪的事情 .