ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   newbie redim question (https://www.excelbanter.com/excel-programming/326471-newbie-redim-question.html)

KR

newbie redim question
 
I need to create a 2-D _public_ array, and the size of the second dimension
needs to be based on a number from one of my procedures- so if I understand
correctly, I need to dim the array at the top of a module to make it public,
then redim it once I know what size the second dimension needs to be.

At the top of my module, I have:
Public ManualDataArray(1 To 2, 1 To 500) As Variant

And within a sub, I try:
ReDim ManualDataArray(1 To 2, 1 To MaxTestRows)

I don't need to preserve anything, as I am redim'ing right before populating
the array.

Unfortunately, when I try to run my sub, I get:
Compile error: Array already dimensioned.

The help file only gives examples of redim'ing a one dimensional array, so I
have no idea how to change the syntax so I can redim this array properly.

I appreciate your help!
Office 2003/Win2000
Keith

p.s. I am making the array public because I need to access it from several
different subs across several different modules. There may be a better way
to set it up, and it may impact the suggested solutions to my problem...I
just don't know the best way to set up my variables to ensure that (when
appropriate) they can be accessed from any of my code within a workbook.

--
The enclosed questions or comments are entirely mine and don't represent the
thoughts, views, or policy of my employer. Any errors or omissions are my
own.



Bob Phillips[_6_]

newbie redim question
 
If you want to make the array dynamic, don't start by dimensioning it

Public ManualDataArray

--

HTH

RP
(remove nothere from the email address if mailing direct)


"KR" wrote in message
...
I need to create a 2-D _public_ array, and the size of the second

dimension
needs to be based on a number from one of my procedures- so if I

understand
correctly, I need to dim the array at the top of a module to make it

public,
then redim it once I know what size the second dimension needs to be.

At the top of my module, I have:
Public ManualDataArray(1 To 2, 1 To 500) As Variant

And within a sub, I try:
ReDim ManualDataArray(1 To 2, 1 To MaxTestRows)

I don't need to preserve anything, as I am redim'ing right before

populating
the array.

Unfortunately, when I try to run my sub, I get:
Compile error: Array already dimensioned.

The help file only gives examples of redim'ing a one dimensional array, so

I
have no idea how to change the syntax so I can redim this array properly.

I appreciate your help!
Office 2003/Win2000
Keith

p.s. I am making the array public because I need to access it from several
different subs across several different modules. There may be a better way
to set it up, and it may impact the suggested solutions to my problem...I
just don't know the best way to set up my variables to ensure that (when
appropriate) they can be accessed from any of my code within a workbook.

--
The enclosed questions or comments are entirely mine and don't represent

the
thoughts, views, or policy of my employer. Any errors or omissions are my
own.






All times are GMT +1. The time now is 08:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com