4

I would like to know if there is an equivalent of Python's pass statement in VBA.

I am using Excel 2016.

user3848207
  • 3,737
  • 17
  • 59
  • 104

4 Answers4

6

The use of Stop (see this answer) seems to be the best thing to do if you are looking for some "non-statement" that you can use to insert a breakpoint, because the Stop command causes the code to break when it is reached, i.e. you don't even need to mark it as a breakpoint because it is one.

You might also like to consider using Debug.Assert some_logical_expression, which will break automatically whenever the logical expression evaluates to False. So Debug.Assert False would be equivalent to Stop, and Debug.Assert x = 3 would be equivalent to If x <> 3 Then Stop.

YowE3K
  • 23,852
  • 7
  • 26
  • 40
5

In Python you need the Pass, because otherwise the methods will not run. In VBA, its perfectly ok if you leave an empty method like this:

Public Function Foo() As String()
End Function
Vityata
  • 42,633
  • 8
  • 55
  • 100
4

Maby you are looking for the "Stop" statement. The good thing about it is that it doesn't clear your variables.

Dominik
  • 43
  • 5
1

It depends what are you trying to achieve.

You may declare a Label and then use GoTo Label e.g. declare a label (like Skip:)in your code where you want to jump if a condition is met and then use GoTo Skip

Below is the small demo code to give you an idea about this...

Dim i As Long
For i = 1 To 10
    If i = 5 Then GoTo Skip
    MsgBox i
Next i
Skip:
Subodh Tiwari sktneer
  • 9,906
  • 2
  • 18
  • 22