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


This is my best guess on how to do this:

Dim testvalue, testarray()
For testvalue = 50 To 100 Step 5
ReDim Preserve testarray(UBound(testarray) + 1)
testarray(UBound(testarray)) = testvalue
Next testvalue

So the goal is to start with an array of unknown size and simply add values
until complete.

I am sure this is very flawed. Would appreciate any help.

Will

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Append to an array


What is wrong with your code. It is not flawed.

I found the code below to be useful. You code created an extra item in the
array. When you do redim testarray(1) it really creates two items in the
array. A zero index and a one index. My code makes the aray exactly the
same size as the data that is inside. it really doesn't make a difference
except when you create a UDF function. then it sometimes matters. for
example you returned an array to the worksheet function Average. The average
would not be correct because you would be dviding by one more item then you
really had.

Sub test()

Dim testvalue, testarray

For testvalue = 50 To 100 Step 5
If IsArray(testarray) Then
ReDim Preserve testarray(0 To (UBound(testarray) + 1))
Else
ReDim testarray(0 To 0)
End If
testarray(UBound(testarray)) = testvalue
Next testvalue

End Sub

"maweilian" wrote:

This is my best guess on how to do this:

Dim testvalue, testarray()
For testvalue = 50 To 100 Step 5
ReDim Preserve testarray(UBound(testarray) + 1)
testarray(UBound(testarray)) = testvalue
Next testvalue

So the goal is to start with an array of unknown size and simply add values
until complete.

I am sure this is very flawed. Would appreciate any help.

Will

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 806
Default Append to an array

Hello Will,

Nothing wring with your code, I think.

Its just the question how much effort you want to invest into your
approach.

An example I developed you can see he
http://www.sulprobil.com/html/pstat.html

Regards,
Bernd
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
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R[_2_] Excel Programming 3 November 13th 07 04:08 PM
Append One Array to Another, and Consolidate Stratuser Excel Programming 47 November 25th 06 07:26 AM
Trying to append to file using an array Susan Hayes Excel Programming 1 January 5th 06 08:55 AM
Append data from a column to separate table array miss_q Excel Programming 5 December 12th 05 11:01 PM
how to know which row to append for the last row tango Excel Programming 2 October 16th 04 02:23 PM


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