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

i'm starting vba, and i'm having problem with this code
i wanted that it automatically calcule the size of the array, based on
the condition "Quente", then it should be copying one matrix 2xN ,
and moving to one dimensional array, so that i can output the resul in
ascending order on the colunn j

can anyone help me? i don't know what i'm doing wrong here

Public Sub org()

Dim tempVar As Integer
Dim anotherIteration As Boolean
Dim I As Integer
Dim arraySize As Integer
Dim myArray(), myArray2(), quente(), frio(), frio2() As Integer
''-----------
''Get the array size.
''-----------
I = 3

If Cells(I, "E").Value = "Quente" Then

Do
arraySize = J
arraySize = arraySize + 1
I = I + 1
J = J + 1
Loop Until Cells(I, "E").Value = ""
End If

ReDim myArray(arraySize - 1)
''---------------------
''Get the values. Convert text to numbers.
''---------------------
For I = 0 To arraySize

If Cells(I, "E").Value = "Quente" Then
For J = 0 To arraySize
myArray(I) = Val(Cells(3 + J, "B").Value)
myArray(I + 1) = Val(Cells(3 + J, "c").Value)
I = I + 2
J = J + 1
Next J

End If

Next I
Do
anotherIteration = False
For I = 0 To arraySize - 2
If myArray(I) myArray(I + 1) Then
tempVar = myArray(I)
myArray(I) = myArray(I + 1)
myArray(I + 1) = tempVar
anotherIteration = True
End If
Next I

Loop While anotherIteration = True
''------------
''Write data to column J.
''------------
For I = 3 To arraySize
Cells(I, "j").Value = myArray(I - 1)
Next I
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Dynamic array

This might get you started on loading the array

I = 3

If Cells(I, "E").Value = "Quente" Then

ReDim myArray(0 To 1, 0 To 0)
Do
I = I + 1
If Cells(I, "E").Value < "" Then
ReDim Preserve myArray(0 To 1, 0 To arraySize)
myArray(0, arraySize) = Cells(I, "B").Value
myArray(1, arraySize) = Cells(I, "C").Value
arraySize = arraySize + 1
End If
Loop Until Cells(I, "E").Value = ""
End If


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



wrote in message
ups.com...
i'm starting vba, and i'm having problem with this code
i wanted that it automatically calcule the size of the array, based on
the condition "Quente", then it should be copying one matrix 2xN ,
and moving to one dimensional array, so that i can output the resul in
ascending order on the colunn j

can anyone help me? i don't know what i'm doing wrong here

Public Sub org()

Dim tempVar As Integer
Dim anotherIteration As Boolean
Dim I As Integer
Dim arraySize As Integer
Dim myArray(), myArray2(), quente(), frio(), frio2() As Integer
''-----------
''Get the array size.
''-----------
I = 3

If Cells(I, "E").Value = "Quente" Then

Do
arraySize = J
arraySize = arraySize + 1
I = I + 1
J = J + 1
Loop Until Cells(I, "E").Value = ""
End If

ReDim myArray(arraySize - 1)
''---------------------
''Get the values. Convert text to numbers.
''---------------------
For I = 0 To arraySize

If Cells(I, "E").Value = "Quente" Then
For J = 0 To arraySize
myArray(I) = Val(Cells(3 + J, "B").Value)
myArray(I + 1) = Val(Cells(3 + J, "c").Value)
I = I + 2
J = J + 1
Next J

End If

Next I
Do
anotherIteration = False
For I = 0 To arraySize - 2
If myArray(I) myArray(I + 1) Then
tempVar = myArray(I)
myArray(I) = myArray(I + 1)
myArray(I + 1) = tempVar
anotherIteration = True
End If
Next I

Loop While anotherIteration = True
''------------
''Write data to column J.
''------------
For I = 3 To arraySize
Cells(I, "j").Value = myArray(I - 1)
Next I
End Sub



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
Need help with dynamic array Peter Bernadyne[_5_] Excel Programming 4 March 12th 06 02:28 PM
Dynamic Array Michael168[_82_] Excel Programming 1 June 2nd 04 07:26 AM
Dynamic 2D Array ExcelMonkey[_52_] Excel Programming 4 January 31st 04 09:32 PM
Dynamic Array dan Excel Programming 4 January 27th 04 04:16 PM
see if dynamic array used RobcPettit Excel Programming 2 January 17th 04 12:44 AM


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

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"