VBA - Passing Values by reference; Why doesnt it work??
Posted by John A. McGraw on January 08, 2002 9:43 PM
I am trying to manipulate a variable from a calling procedure in the called procedure. I cant get it to work! MS Help says:
"As a result, the variable's actual value can be changed by the procedure to which it is passed. Unless otherwise specified, arguments are passed by reference."
But for example, in the following simple code, this does not seem to be the case:
Dim i As Integer
i = 10
Sub sub2(ByRef i as Integer)
i = 20
If I run "sub1", both message boxes show "10". Why was sub2 not able to change i to 20? I cant figure it out! VBA Help, like I quoted above, said that it should!