我在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“赶上”并正确添加?这是一个已知问题吗?
感谢您的帮助。显然,我的解决方案不是永久性解决方案,并且我很想知道为什么会发生这种奇怪的事情。