【问题标题】:VBA Step Into Skipping For LoopVBA 进入跳过循环
【发布时间】:2016-11-11 23:04:15
【问题描述】:

我开始使用这个“向导”文件来自动化一些 Excel (2016) 任务,但我在 VBA (7.1) 中的 Step Into 工具中遇到了问题。这是我的代码:

Public LastInitial As Integer

Sub FormatRecipeFile()

    'Get the row number of the last 
    'initial listed in column D:
    LastInitial = Range("D" & Rows.Count).End(xlUp).Row

    'Prints "9" in cell F5:
    Range("F5").Value = LastInitial

    'The first initial is cell D3, so set j to 3:
    For j = 3 To LastIntitial
        'Set each intial to a new value:
        Range("D" & j).Value = Range("D" & j).Value & " (done)"
    Next j

End Sub

公共变量必须是公共的以供将来使用。在 F5 中打印“9”是我检查 For 循环中是否有要循环的项目的方法。

问题是,当按 F8 时,每一行代码都执行得很好,它甚至会突出显示“For j = 3 To LastInitial”,但是当我再次按 F8 时,它会跳到“End Sub”而不运行任何内容For 循环。

【问题讨论】:

    标签: vba excel for-loop step-into


    【解决方案1】:

    您好,您的行中似乎有错字

    For j = 3 To LastIntitial
    

    应该是这样的

    For j = 3 To LastInitial
    

    【讨论】:

    • 又一个程序员被Option Explicit987654323@使用失败所困扰
    猜你喜欢
    • 1970-01-01
    • 2017-04-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 2013-04-23
    相关资源
    最近更新 更多