PDA

View Full Version : Global Variable accross multiple procedures



Mike B
03-19-2007, 01:04 PM
Hi!
I am a new member, also new to VBA. I have a program which was working, however i made modifications and exceeded VBA's size limitation for a single Sub Procedure, therefore I am trying to break the program into five procedures, which I have done. the problem is that i have some variables in the last procedure which gathers the values from the other procedures, I made all of the variables Public trying to increase their lifetime but have not been suscessful. The code structure is:
Sub CalculateTask

Call 1
Call 2
Call 3
Call 4
Call 5
End Sub

Sub 1
Do
code
Loop
End sub
I do this for all five prodcures.

I woud appreciate any help.

Thank you,

Mike B

Ken Puls
03-19-2007, 01:39 PM
Wow! Just how long was that procedure?

To make a variable public, you'd want to declare it as such before your first procedure:
Public sSomething as String

Sub CalculateTask

Call 1
Call 2
Call 3
Call 4
Call 5
End Sub

I'm hoping that your sub names are not really 1,2,3,etc... Give them something a little more meaningfull.

If you're looking for help to make your code more efficient, you might want to try posting some (or your workbook) here as well.

HTH,

Ken Puls
03-19-2007, 01:41 PM
Oh! And an FYI...

The above will make your variable public across all modules. If you only need it in your module, you can declare it as Private instead. Being outside a procedure, it will be accessible to the entire module, but not outside of it.