arrays again

R

RobcPettit

Static Runner() As Variant

idex = idex + 1
A = 13
For I = 1 To 4

A = A + 1
ReDim Preserve Runner(1 To 4, 1 To idex)
Runner(I, idex) = Range("f" & A)
Debug.Print Runner(I, idex)

Next I

Range("t2").Resize(UBound(Runner, 1), 4) =
Application.Transpose(Runner)
Hi, could somebody what Im doing wrong with above. Ive got runner as a
static variable, Im using this in worksheet change so each cell change
idex counts up. Im adding data to runner then transposing to a range
purly to test data is going in ok, wont be doing this in final macro.
When I transpose I only get 4 rows and 4 columns, if I change the 4 to
say 10 then I get 10 cols 6 with n/a in which is what i thought would
happen. I thought i would have had to put the redim as (1 to idex, 1 to
4), but this creates an error. if I increase the the redim (1 to 50, 1
to idex) i get 50 rows, but this doesnt help because anything added
after 50 doesnt show. Any Ideas on what im doing wrong.
Regards Robert
 
T

Tom Ogilvy

The upperbound of dimension1 is 4 but you want to use the upperbound of
dimension 2 in your transpose assignment. Also, don't redim inside your loop
since there is nothing changing inside the loop that would require a redim.

idex = idex + 1
ReDim Preserve Runner(1 To 4, 1 To idex)
A = 13
For I = 1 To 4
A = A + 1
Runner(I, idex) = Range("f" & A)
Debug.Print Runner(I, idex)
Next I

Range("t2").Resize(UBound(Runner, 2), 4) = _
Application.Transpose(Runner)
 
R

RobcPettit

Thankyou Tom. Thats sorted it perfect. Im slowly getting to grips with
these arrays.
Regards Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

print values in an array 2
averaging arrays 2
Parsing XML with VBA 0
re write 2
Remove Identical words 0
Cases within Cases 7
Still Having Trouble with Combo Box 8
Using excel to work out trifectas 0

Top