相关疑难解决方法(0)

如何迭代动态增加的字典?似乎 excel VBA 预编译 For 循环的“限制”

我的 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)

excel vba

2
推荐指数
1
解决办法
1890
查看次数

更新for循环的条件

更新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.
这可以解决一些怎样的问题?

excel vba excel-vba

1
推荐指数
1
解决办法
169
查看次数

标签 统计

excel ×2

vba ×2

excel-vba ×1