View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban[_4_] Alan Beban[_4_] is offline
external usenet poster
 
Posts: 171
Default Populating a 2-D array

Tom Ogilvy wrote:
Also, you had L3 as one of your values. I assumed you wanted
the len("L3") since that followed your pattern.


And if instead you wanted the name in Cell L3 of the active sheet
instead of the length of the text string L3, you can add the following
just before End Sub:

varr(10,1) = Range("L3") .Value

Alan Beban

Using evaluate instead of square brackets might be a little more friendly:

Sub SetArray()
Dim sVal As String, sStr As String
Dim i As Long, j As Long
sVal = "6,1,5,6;5,1,5,25;4,1,5,43;7,1,6,10;5,3,6,38;" & _
"5,1,7,12;3,1,7,32;5,1,7,50;4,5,9,18;2,1,18,31;3,1 ,21" & _
",28;5,1,23,12"
varr = Evaluate("{" & sVal & "}")
For i = LBound(varr, 1) To UBound(varr, 1)
sStr = ""
For j = LBound(varr, 2) To UBound(varr, 2)
sStr = sStr & varr(i, j) & ", "
Next
Debug.Print Left(sStr, Len(sStr) - 2)
Next
End Sub
Note that in my experience, this is only useful for small strings of values.
Less than around 128 characters as I recall. Your array is up to about 109
characters. Also, you had L3 as one of your values. I assumed you wanted
the len("L3") since that followed your pattern.