Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default 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
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
How to give values to a range? pemt Excel Discussion (Misc queries) 0 July 24th 09 04:14 AM
v-Lookup between values and give result -Help Yossy Excel Worksheet Functions 4 January 15th 09 05:43 PM
How to Add 21 Textbox values to give the Sum ? Corey Excel Programming 8 December 27th 06 07:49 PM
Array formula to give blank Joanne Ramaekers Excel Worksheet Functions 6 June 20th 06 03:32 AM
What formula will read 2 separate values and give me a 3rd value? VinnyG Excel Programming 1 May 13th 05 09:25 PM


All times are GMT +1. The time now is 01:41 PM.

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"