declaring a public array

  • Thread starter Thread starter JT
  • Start date Start date
J

JT

I want to declare a 2 dimension public array but am having
trouble with the syntax because one of the dimensions
contains a variable.

This what I have so far:

Public MyArray (1 to 3, 1 to LastRow) but I get and error
message because it wants a constant instead of the
variable.

Can I do this? Any suggestions would be appreciated.
Thanks
 
Hi
as you can't use a variable in thie declaration statement try something
different. e.g.

public MyArray()

'...other global declarations

Public Sub Initialize()
Dim lastrow

lastrow = 10
ReDim MyArray(1 to 3, 1 to lastrow)
'...
end sub
 
JT,

Declare the array as a dynamic array, and then size it later in
code. E.g,

Public Arr() As Long

Sub AAA()
Dim N As Long
N = 100
ReDim Arr(1 To 3, 1 To N)
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
This is presumably because LastRow has not value until you run code.

Try declaring it as Public MyArray() and then when you set LastRow withg a
value, ReDim it

ReDim MyArray(1 To 10, 1 To lastrow)
 

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

Back
Top