有没有一种方法可以跳到VBA中的特定行

时间:2018-08-10 21:31:49

标签: excel vba excel-vba if-statement

如果不满足某些条件,我正在寻找一种方法来跳到最后。我只是在为家庭项目学习VBA代码,这是非常新的。这就是我所拥有的。

scipy.ndimage.filters.convolve

如果单元格A8为空白,我想等待8分钟,然后从刷新开始Sub Macro1() ' Some stuff here Sheets("Sheet1").Select ActiveWorkbook.RefreshAll If Sheets("Sheet1").Range("A8") <> "" Then GoTo Line122 Else ' Do all this if the condition is false End If ' There is more in between ' I want to skip to here Call Test End Sub Sub Test() Application.OnTime Now + TimeValue("00:08:00"), "Macro1" End Sub 。在条件检查之后,如何跳过其余的代码并直接从Macro1行继续?

3 个答案:

答案 0 :(得分:0)

也许您需要这个

Sheets("Sheet1").Select
ActiveWorkbook.RefreshAll

If Sheets("Sheet1").Range("A8") <> "" Then
    Call Test
    Exit Sub
Else
    'Do all this if the condition is false
End If

答案 1 :(得分:0)

GoTo告诉VBA跳过代码中的行标签,而不是特定的行。有关其他示例,请查看code at this bottom of this documentation.

Sub MainSub()
    Sheets("Sheet1").Select
    ActiveWorkbook.RefreshAll

    If Sheets("Sheet1").Range("A8") <> "" Then
        GoTo mytag
    Else
        'Do all this if the condition is false
    End If

    ' More code in here

mytag:
    Call test

End Sub


Sub test()
    Application.OnTime Now + TimeValue("00:08:00"), "Macro1"
End Sub

答案 2 :(得分:0)

具有所需功能的代码如下:

Sub Macro1()

    ' Some stuff here

    Sheets("Sheet1").Select
    ActiveWorkbook.RefreshAll

    If Not Sheets("Sheet1").Range("A8") <> "" Then
        ' Do all this if the condition is false
        ' There is more in between
    End If

    ' I want to skip to here
    Call Test

End Sub

Sub Test()

    Application.OnTime Now + TimeValue("00:08:00"), "Macro1"

End Sub