View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Sam Wilson Sam Wilson is offline
external usenet poster
 
Posts: 523
Default Procedure level array not recognised at module level

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.

"Numskull" wrote:

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?