GoTo in VBA

后端 未结 5 2114
情书的邮戳
情书的邮戳 2021-02-16 00:10

From the VBA help file:

GoTo Statement

Branches unconditionally to a specified line within a procedure.

Syntax<

5条回答
  •  广开言路
    2021-02-16 00:42

    Sub Jump()
    10 Dim A As Integer
    20 A = 25
    30 GoTo 50
    40 A = 50
    50 Debug.Print A
    End Sub
    

    It's a throwback to the old (really old) BASIC days, where line numbers were required. Now labels are used.

    Sub Jump2()
       Dim A As Integer
       A = 25
       GoTo JumpToHere
       A = 50
    JumpToHere:
       Debug.Print A
    End Sub
    

    But using GoTo is considered poor programming, with the exception of OnError GoTo ...

提交回复
热议问题