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

Excel 2002, WinXP
Let's say I have an array, MyArray, consisting of A, B, C. (Strings only)
Now lets say that I want to build another array, OtherArray, consisting of
the same A, B, C, but having D as well. I know that I can build the
OtherArray as simply A, B, C, D but I don't want to do that. I want to
build the OtherArray by referencing MyArray and tacking D on to it.
How do I code the building of the OtherArray by using MyArray and D?
Thanks for your help. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Adding to an array

If you are sure you need both arrays:

Sub Test()
Dim Array1() As String
Dim Array2() As String

ReDim Array1(1 To 3)
For i = 1 To 3
Array1(i) = Format$(i)
Next i

Array2 = Array1
ReDim Preserve Array2(1 To UBound(Array2) + 1)
Array2(4) = "4"

For i = 1 To UBound(Array2())
Debug.Print Array2(i)
Next i
End Sub

You can also copy the values from Array1 to Array2, one element at a time, in
a For/Next loop, i.e.

For i = 1 to Ubound(Array1())
Array2(i) = Array1(i)
Next i

On Sun, 24 Oct 2004 12:52:32 -0400, "Otto Moehrbach"
wrote:

Excel 2002, WinXP
Let's say I have an array, MyArray, consisting of A, B, C. (Strings only)
Now lets say that I want to build another array, OtherArray, consisting of
the same A, B, C, but having D as well. I know that I can build the
OtherArray as simply A, B, C, D but I don't want to do that. I want to
build the OtherArray by referencing MyArray and tacking D on to it.
How do I code the building of the OtherArray by using MyArray and D?
Thanks for your help. Otto


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

PS: DO you need a 2nd array? As long as the first was defined as a dynamic
array (no subscripts in the DIM statement, just in a REDIM statement), you can
always change the size of the right-most dimension, up or down, without losing
data, with the REDIM PRESERVE statement.

On Sun, 24 Oct 2004 12:52:32 -0400, "Otto Moehrbach"
wrote:

Excel 2002, WinXP
Let's say I have an array, MyArray, consisting of A, B, C. (Strings only)
Now lets say that I want to build another array, OtherArray, consisting of
the same A, B, C, but having D as well. I know that I can build the
OtherArray as simply A, B, C, D but I don't want to do that. I want to
build the OtherArray by referencing MyArray and tacking D on to it.
How do I code the building of the OtherArray by using MyArray and D?
Thanks for your help. Otto


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Adding to an array

Hi Otto,

here is one way

myArray1 = Array("A", "B", "C")
myArray2 = myArray1
ReDim Preserve myArray2(LBound(myArray2) To UBound(myArray2) + 1)
myArray2(UBound(myArray2)) = "D"

--

HTH

RP

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
Let's say I have an array, MyArray, consisting of A, B, C. (Strings only)
Now lets say that I want to build another array, OtherArray, consisting of
the same A, B, C, but having D as well. I know that I can build the
OtherArray as simply A, B, C, D but I don't want to do that. I want to
build the OtherArray by referencing MyArray and tacking D on to it.
How do I code the building of the OtherArray by using MyArray and D?
Thanks for your help. Otto




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Adding to an array

Myrna, Bob
Thanks for your help. Otto
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
Let's say I have an array, MyArray, consisting of A, B, C. (Strings only)
Now lets say that I want to build another array, OtherArray, consisting of
the same A, B, C, but having D as well. I know that I can build the
OtherArray as simply A, B, C, D but I don't want to do that. I want to
build the OtherArray by referencing MyArray and tacking D on to it.
How do I code the building of the OtherArray by using MyArray and D?
Thanks for your help. Otto





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Adding to an array

Otto Moehrbach wrote:

Excel 2002, WinXP
Let's say I have an array, MyArray, consisting of A, B, C. (Strings only)
Now lets say that I want to build another array, OtherArray, consisting of
the same A, B, C, but having D as well. I know that I can build the
OtherArray as simply A, B, C, D but I don't want to do that. I want to
build the OtherArray by referencing MyArray and tacking D on to it.
How do I code the building of the OtherArray by using MyArray and D?
Thanks for your help. Otto


For another approach, if the functions in the freely downloadable file
at http://home.pacbell.net/beban are available to your workbook

MyArray2 = MakeArray(MyArray,"D",1)

Alan Beban
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
Adding if to Average If Array function Diddy Excel Worksheet Functions 5 December 10th 09 03:45 PM
Adding up with array formula vsoler Excel Worksheet Functions 2 May 26th 07 02:30 AM
adding cells within an array beecher Excel Worksheet Functions 11 August 30th 06 08:29 AM
Adding rows to an array chris w Excel Worksheet Functions 1 December 10th 04 02:27 AM
Adding an Array James Stephens[_3_] Excel Programming 2 January 14th 04 12:51 PM


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