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

Efficient Arrays: Setting size equal to count?
If I have an array that, based on the data loaded to the program, could need
to be rather small(10) or very large (10000), if there a way to selectively
set the size.

If I made the array dynamic, can I redim = count where count is a variable
based on the number of rows in a column?

Or is there no harm in dim an array as very large an only using a small part
of it? Does the unused portion pose a large drain on resources?

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

Always best to set as required, it is a once-off operation.

As you guessed, you can ReDim it

Dim ary()
Dim rng As Range

Set rng = Range("A1:A100")

ReDim ary(1 To rng.Rows.Count)


or more dynamically

Dim ary()
Dim iLAstRow As Long

iLastRow = Cells(Rows.Count,"A").End(xlUp).Row

ReDim ary(1 To iLastRow)


You can even change it later if need be, and preserve the contents

ReDim Preserve ary(1 To 100)

--

HTH

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


"Mark" wrote in message
...
Efficient Arrays: Setting size equal to count?
If I have an array that, based on the data loaded to the program, could

need
to be rather small(10) or very large (10000), if there a way to

selectively
set the size.

If I made the array dynamic, can I redim = count where count is a variable
based on the number of rows in a column?

Or is there no harm in dim an array as very large an only using a small

part
of it? Does the unused portion pose a large drain on resources?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Efficient Arrays?

redim is probably the best option here. If you know the size of the array at
runtime then use the redim statement to set the size. (redim preserve if you
want to change the size of an existing populated array) Don't make an array
the is huge to store a small amount of data. If you do you will not
effectively be able to traverse the array looking for an item in the array.
Also it is a huge waste of memory.
--
HTH...

Jim Thomlinson


"Mark" wrote:

Efficient Arrays: Setting size equal to count?
If I have an array that, based on the data loaded to the program, could need
to be rather small(10) or very large (10000), if there a way to selectively
set the size.

If I made the array dynamic, can I redim = count where count is a variable
based on the number of rows in a column?

Or is there no harm in dim an array as very large an only using a small part
of it? Does the unused portion pose a large drain on resources?

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
Efficient linking teh_chucksta Excel Discussion (Misc queries) 3 April 18th 08 11:44 PM
What is more efficient Brad Excel Discussion (Misc queries) 2 November 20th 06 09:13 PM
More efficient way? Steph[_3_] Excel Programming 6 June 23rd 04 09:34 PM
Loop more efficient ? farmer[_2_] Excel Programming 4 June 21st 04 06:51 AM
Which is more efficient? Norm[_5_] Excel Programming 3 April 2nd 04 04:24 PM


All times are GMT +1. The time now is 04:52 AM.

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"