If you need a procedural level variable to retain its value between calls to the procedure, declare the variable using the Static keyword : Static variable « Language Basics « VBA / Excel / Access / Word






If you need a procedural level variable to retain its value between calls to the procedure, declare the variable using the Static keyword

 
Private Sub MyProcedure2()
     Static myVar As Integer
     myVar = myVar + 1
End Sub

 








Related examples in the same category

1.Static variable lifetime
2.Static Variables: A Special Type of Local Variable
3.Redefine static variable