Procedure level array not recognised at module level

N

Numskull

I wonder if anybody can explain this?

In developing a new program I declared a variable with indeterminate
dimension at module level (to make it available to any procedure) (e.g. Dim
variable() ).
I then reDimmed it at procedure level (to reinitialise the values before
working with it – i.e. reDim variable(array size)).
Then I used it within another procedure (e.g. sub AnotherProcedure()…….
variable(subscript) = a value……end sub, and it worked exactly as expected.

I then renamed "AnotherProcedure()" as I had rejigged the flow of the
program e.g. to sub DifferentName, only to find that it no longer recognised
the Dimmed variable within the module and came out with an error (subscript
out of range).

I then decided instead to create a new procedure with the required name,
then copy the old contents into it and it worked fine again!!

Is there a reason for this or is it some unknown quirk of Excel VBA?
 
S

Sam Wilson

Have you declared the variable as public eg:

Public variable() as variant in you rmodule level declaration? If you
haven't, and haven't declared "Option Explicit" at the start of your module
that could explain the behaviour.
 
B

Bob Phillips

I cannot reproduce this behaviour.

Can you post a simple example of the code?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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