vba static variable

The solution for “vba static variable” can be found here. The following code will assist you in solving the problem.

‘ Static variable inside a function
Function MyStaticFunction(ByVal pToAdd As Integer) As Integer
Static iStatic As Integer ‘ Keeps its value between calls
iStatic = iStatic + pToAdd
MyStaticFunction = iStatic
End Function
‘———————————————————————
Sub TesMe()
Debug.Print MyStaticFunction(1) ‘ 1
Debug.Print MyStaticFunction(3) ‘ 4
End Sub

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

Similar Posts