Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default declaring a public array

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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default declaring a public array

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


--
Regards
Frank Kabel
Frankfurt, Germany


JT wrote:
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default declaring a public array

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



"JT" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default declaring a public array

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)

--
HTH

-------

Bob Phillips
"JT" wrote in message
...
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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring variables in Module vs. Public Jeff Excel Discussion (Misc queries) 5 November 19th 07 08:27 PM
Q: Declaring a dynamic array Srdjan Kovacevic[_4_] Excel Programming 1 January 16th 04 07:24 PM
Declaring Public Procedure mac Excel Programming 3 December 3rd 03 05:01 PM
declaring an array of CheckBox's Didier Poskin Excel Programming 4 September 9th 03 09:02 AM
Declaring Dynamic Multi-dimensional Array JohnV[_2_] Excel Programming 2 July 15th 03 06:58 PM


All times are GMT +1. The time now is 10:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"