Best way to make variables in one sub available to a called sub
I am working on a complicated Sub. The main For loop is now over two screens long. It's difficult tell how the nested If statements and their Else and End If statements line up. And some of the code is replicated.
So I'd like to move chunks of the code to a sub-Sub. One of these Subs will have to deal with 7-8 variables and modify some of them. I know I can pass these variables to the Sub using the ByRef option, which will allow the Sub to modify them. This is probably the recommended way, but it leads to a fairly long Call statement and I have to make sure that I get them in the right order in both the Call and the Sub statement.
I'd like to play with making them some kind of "public" or "global" variables. I tried changing Dim to Public, but this got an error. I then moved the Dim statements outside the main Sub. That worked, but then all of my variable declarations are not together.
Is there a better way?
Is there a good web page with a clear explanation of variable declaration? I've read several pages from Microsoft, but found them all muddled or incomplete.
Thanks
|