Procedures like variables can be local or global in scope. Local procedures can only be accessed from the module they reside. Local variable can be accessed only from the procedure they are part of.
To achieve the desired objective with the code you would generally need to check for conditions, iterate through arrays and collections or until a condition is met, and assign values to variables. Here’s an example using If … Then and Select … Case constructs to check conditions, Do … Loop and While … Wend constructs to loop until certain conditions are met.