View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default whats wrong with my array?

You are assigning all the values of each cell to each element of the array,
so you end up with the value of the last cell in each element.



Sub showArray()
Dim acell As Variant
Dim mynames(0 To 47)
Dim ncount As Integer
ncount = 0
For Each acell In Range("a3:a50")
mynames(ncount) = acell.Value
ncount = ncount + 1
Next

For i = 0 To UBound(mynames)
If i Mod 10 = 0 And i < 0 Then
sStr = sStr & mynames(i) & vbNewLine
Else
sStr = sStr & mynames(i) & ","
End If
Next
sStr = Left(sStr, Len(sStr) - 1)
MsgBox sStr
End Sub


or

Dim aCell as Range
Dim myNames as Variant
MyNames = Range("A3:A50").Value

Mynames no holds a two dimensional array

MyNames(1 to 48, 1 to 1

Sub showArray()
Dim aCell As Range
Dim myNames As Variant
myNames = Range("A3:A50").Value

For i = 1 To UBound(myNames)
If i Mod 10 = 0 Then
sStr = sStr & myNames(i, 1) & vbNewLine
Else
sStr = sStr & myNames(i, 1) & ","
End If
Next
sStr = Left(sStr, Len(sStr) - 1)
MsgBox sStr
End Sub


--
Regards,
Tom Ogilvy



"joshashcraft" wrote in message
...
i have these two arrays both in one of my subs in my
worksheet, why won't they load the values?
Basically, i want it to cycle through the range below for
each, pull the value, and stick them in each of the arrays.
any help would be much appreciated!
thanks guys,
Josh


Dim acell As Variant
Dim mynames(0 To 49)
Dim ncount As Integer
For Each acell In Range("a3:a50")
For ncount = 0 To 49
mynames(ncount) = acell.Value
Next ncount
Next


Dim bcell As Variant
Dim mystatus(0 To 49)
Dim scount As Integer
For Each bcell In Range("b3:b50")
For scount = 0 To 49
mystatus(scount) = bcell.Value
Next scount
Next