View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1938_] Rick Rothstein \(MVP - VB\)[_1938_] is offline
external usenet poster
 
Posts: 1
Default Give array values

You can use a structure like this to load up your array...

Const NumberOfRows As Long = 6
Const NumberOfCols As Long = 6
Dim ColNum As Long
Dim RowNum As Long
Dim Temp() As String
Dim MyData(1 To NumberOfRows, 1 To NumberOfCols) As String
Temp = Split("New York,France,John,..etc...,Radio", ",")
For ColNum = 1 To NumberOfCols
For RowNum = 1 To NumberOfRows
MyData(RowNum, ColNum) = Temp(NumberOfCols * (RowNum - 1) + ColNum - 1)
Next
Next
Erase Temp

This works as long both dimensions of the MyData array start with 1....
simply assign the number of rows and columns to the appropriate Const
statements and put your list of items (across each row, column-by-column
ordering), comma delimited, into the first argument of the Split function
(do not try to pretty things up by placing spaces around the delimiter; and,
if any of your items have internal commas, you will need to use a different
delimiter, one that is not included within any items in the list, and change
the second argument of the Split function to reflect what it is).

Rick


"shapper" wrote in message
...
Hello,

I created an array of string as follows:

Dim MyData(1 To 6, 1 To 6) As String

Then I gave values to the 36 array elements as follows:
MyData(1,1) = "New York"
MyData(1,2) = "France"
MyData(1,3) = "John"
...
MyData(6,6) = "Radio"

Is there a way to fill the 36 elements instead of using one code line
for each array element?

Thanks,
Miguel