Question What determines if publlic variable content is destroyed

M

mcambrose

I have some code that creates an array public variable and then saves some
values to this variable. When I end this subroutine, I can look at the
immediate window and check the contents and it is available. I have another
subroutine that uses the same code, but it also has a userform in it. When
the second routine finishes, the variable contents are destroyed. Is there
something about userforms that messes with variables.
 
D

Dave Peterson

If you click the Reset button (or Run|reset in the menu), then the variables
will be reset.

If you have End (not "end if", "end sub", "end select", ...), you'll be stopping
the macro, but also reseting the variables.
 
M

mcambrose

Thanks for taking the time to answer. I checked the variable at the last
statement prior to "end sub" and it is still there as expected. Once I
execute "end sub" the variable is gone.
In a subroutine in another workbook I also checked the variable before "end
sub" and it is available as expected, however after I execute the "end sub"
it is still available. Any idea how these two could be different? In both
instances I checked just before the "end sub" and just after it. Thanks for
any suggestions.
 
M

mcambrose

Thanks. The variable that is being destroyed is declared as public at the top
of the module in both cases I describe.
 
J

Joel

If you need to pass data betwen uerforms create a text box on the userform
and make the textbox Visible parameter False. Then use the Text box as a
parameter list to pass data between userforms. I had your problem beofre an
that is how I solved the problem. If you have an array use the Join and
split functions save and recal an arran of data to/from a string.
 
D

Dave Peterson

I don't have a guess.

Can you skinny down the code so that it only shows the problem and post it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top