Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) | Excel Programming | |||
Append One Array to Another, and Consolidate | Excel Programming | |||
Trying to append to file using an array | Excel Programming | |||
Append data from a column to separate table array | Excel Programming | |||
how to know which row to append for the last row | Excel Programming |