我的 VBA 代码中的 Scripting.Dictionary 对象正面临这个奇怪的问题。我希望继续遍历字典的总长度。我可能会在循环内向字典中添加更多项目,因此字典的大小可以动态变化,可以这么说。似乎它只迭代字典中最初的元素而不是新元素!
这是代码:
'Recursively continue to get all dependencies
numberOfPreReqsToIterate = preReqGraph.Count - 1
For preReqCount = 0 To numberOfPreReqsToIterate
listOfPreReqs = preReqGraph.items
rowNumberOfDependency = Application.WorksheetFunction.Match(listOfPreReqs(preReqCount), Range("requirementNumber"), 0)
listOfPreReqsForCurrentPreReq = Application.WorksheetFunction.Index(Range("preReqList"), rowNumberOfDependency)
If listOfPreReqsForCurrentPreReq <> "" Then
preReqs = Split(listOfPreReqsForCurrentPreReq, ",")
'Add each prereq to dictionary
For i = 0 To UBound(preReqs)
'If prereq already exists implies cycle in graph
If preReqGraph.Exists(Trim(preReqs(i))) Then
MsgBox ("YOU HAVE A CYCLE IN PREREQUISTE SPECIFICATION!")
End
End If
'If not then …Run Code Online (Sandbox Code Playgroud) 更新for循环条件是否可行?
我需要从第1行循环到第1页的lastrow,当条件满足时我需要切换表并循环到该表的末尾.
仅用于演示:
lr = 5
For i = 1 To lr
If i = 3 Then
lr = 500
i = 50
End If
Next i
Run Code Online (Sandbox Code Playgroud)
这段代码的结尾是i=51因为for循环在它结束之前没有更新它的条件Next i.
这可以解决一些怎样的问题?