Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Give array values
Or, if the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook Temp = Split("New York, France, John, etc, Radio", ",") arr = ArrayReshape(Temp, 6, 6) Alan Beban Rick Rothstein (MVP - VB) wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to give values to a range? | Excel Discussion (Misc queries) | |||
v-Lookup between values and give result -Help | Excel Worksheet Functions | |||
How to Add 21 Textbox values to give the Sum ? | Excel Programming | |||
Array formula to give blank | Excel Worksheet Functions | |||
What formula will read 2 separate values and give me a 3rd value? | Excel Programming |