Pass VBA Variables Between Macros
In Excel you can pass variables (an argument) between macros at run time. The following is an example of the syntax;
The information between the brackets is known as an Argument. There needs to be two procedures, A Calling Procedure and a Called Procedure. The Calling Procedure is the one where the Variable is passed from and the Called Procedure is the one the Variable is passed to.
The following is a very simple example of passing one parameter between a Calling Procedure to the Called Procedure (the procedure with the arguments);
Sub UseVar(ByVal Col as Integer) 'VBA Called Procedure
rng.Copy rng.Offset(, 1)
In the above example there is just one Argument and it is an Integer. An important point is the arguments type must match. So if the variable is declared as an integer it cannot be passed as a String for example.
The following is an example of a VBA procedure which passes two Variables;
Dim str As String
Call AddVal(rng, str)
Sub AddVal(ByRef rng As Range, ByVal str As String)
In the above example the Range (rng) will be transferred from CallingPro to the first argument of the AddVal procedure and the String (Str) will be transferred to the second argument of the AddVal procedure.