ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping data out of array (https://www.excelbanter.com/excel-programming/352280-looping-data-out-array.html)

gti_jobert[_8_]

Looping data out of array
 

Hi all,

the code below, loops data from my userform into an array, I have
posted this on here before but am going to elaborate a little more in
this thread;


Code:
--------------------

Static Counter As Long
Static sizeofarray As Long

Counter = Counter + 1
ReDim Preserve ary(1 To 3, 1 To 3, 1 To Counter)

flag = False

For i = 1 To 3

ary(1, i, Counter) = MachineNumber
ary(2, i, Counter) = Controls("lblDTCode" & i).Caption
ary(3, i, Counter) = Controls("lblDTDuration" & i).Caption

If ary(2, i, Counter) < "" Then

sizeofarray = sizeofarray + 1
aryCount = sizeofarray

End If

flag = True

Next i

--------------------


As stated in previous post, the code above works fine, looping it back
out is the problem;


Code:
--------------------

For r = 0 To aryCount

p = 1
q = 0
Do

If ary(2, p, i) < "" Then

ActiveCell.Offset(r, 6) = ary(2, p, i)
ActiveCell.Offset(r, 7) = ary(3, p, i)

End If

p = p + 1
q = q + 1
Loop Until p = 4

Next r

--------------------


It seems I need a nested loop for 3 variables (i, r, and p) where i
loops through 1-6, r loops through 0-18 and p loops through 1-3. Anyone
out there got any clue?

I am going to stick with a 3d array btw, seems the most appropriate for
the data. Thanks all


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=508000



All times are GMT +1. The time now is 02:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com