Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Dimensioning Arrays

I think I need to use an array, but it insists I use 'constant' expressions
when declaring the array, but I want to change its size depending on the
data in use. ReDim would seem an appropriate option, but that too wants
constant expressions and hence I cannot use variables to define the required
size.

Is this a limitation of VBA (I find hard to believe) or have I missed
something obvious?

Thank

Peter M


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Dimensioning Arrays

Peter,

You can use a variable. This little example shows that you can do that,
using an element of the same array itself

Dim av() As Long

ReDim av(3)
av(0) = 1
av(1) = 2
av(2) = 3
av(3) = 4
ReDim Preserve av(av(3))
av(4) = 9
MsgBox av(4)

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Peter M" wrote in message
...
I think I need to use an array, but it insists I use 'constant'

expressions
when declaring the array, but I want to change its size depending on the
data in use. ReDim would seem an appropriate option, but that too wants
constant expressions and hence I cannot use variables to define the

required
size.

Is this a limitation of VBA (I find hard to believe) or have I missed
something obvious?

Thank

Peter M




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Dimensioning Arrays

Declare the array without dimensions first:

Dim arr()
ReDim arr(1 to 3)

Alan Beban

Peter M wrote:
I think I need to use an array, but it insists I use 'constant' expressions
when declaring the array, but I want to change its size depending on the
data in use. ReDim would seem an appropriate option, but that too wants
constant expressions and hence I cannot use variables to define the required
size.

Is this a limitation of VBA (I find hard to believe) or have I missed
something obvious?

Thank

Peter M



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
VBA arrays Matt Excel Discussion (Misc queries) 3 February 22nd 09 06:36 PM
Arrays Abdul Shakeel Excel Worksheet Functions 1 December 12th 08 10:24 AM
Use of IF with arrays Andrew L Excel Worksheet Functions 5 August 15th 08 10:15 PM
Range Naming, dimensioning contiw New Users to Excel 1 August 3rd 07 12:23 AM
Need help with arrays (I think) rbhedal Excel Worksheet Functions 3 October 19th 05 07:24 AM


All times are GMT +1. The time now is 07:47 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"