Thread: Array question
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Array question

Dim myArray()
redim myArray(0 to 0)

do
res = Inputbox("Enter a Letter, click cancel to quit")
if res = "" then exit do
if not isempty(myArray(ubound)) then
redim preserve MyArray(0 to ubound(myArray) + 1)
end if
myArray(ubound(myArray)) = res
Loop While True

for i = lbound(myArray) to ubound(myArray)
Range("A1").offset(i,0).Value = myArray(i)
Next


There are other ways, like in the initial redim, making an array larger than
you need, then after looping, redim preserve it down to the size you used.
You can also use application.Transpose to put the array down on the
worksheet in on command. But this should get you started.

--
Regards,
Tom Ogilvy


"mickiedevries " wrote in
message ...
I need help in my program, what I need to do is assign variables to an
array and then have the array display on a worksheet one element of the
array to a row.

For example if option one is selected then variables A, B, and C need
to be assigned to the same array. The problem is I don't know what the
total number of elements that will need to be stored in the array will
be because it is dependent on the user's choices and will change each
time the program is ran. I have been reading about ReDim Preserve, but
I can't put it all together yet to work.

Then the total elements must display on the worksheet with for example
the array element containing variable A on line one, variable B on line
two, etc. until all the elements in the array are displayed. I'm new at
this so I'm stuck:)

Thanks for any help

Mickie


---
Message posted from http://www.ExcelForum.com/