Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Transfer data from worksheet to array

i need to transfer data from excel worksheet to an array. one way to do is
read cell by cell. this works fine but is very time consuming. for example:

Sheet1.Activate
For CounterNumber1 = 1 To 10
For CounterNumber2 = 1 To 10
OriginalMatrix(CounterNumber1, CounterNumber2) =
Sheet1.Cells(CounterNumber1, CounterNumber2).Value
Next CounterNumber2
Next CounterNumber1

is there a way to tranfer the entire range a1 to j10 to the array at a time
so that computation becomes faster. the following code doesn't work:

Sheet1.Activate
OriginalMatrix = Sheet1.Range("a1:j10").value

any suggestions please?

tia
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Transfer data from worksheet to array

So far as I am aware, you must read your data into the array as you are
doing. Placing it back to the worksheet can be done in one step though.

Ken Puls, CMA - Microsoft MVP (Excel)
www.excelguru.ca

Pradip Jain wrote:
i need to transfer data from excel worksheet to an array. one way to do is
read cell by cell. this works fine but is very time consuming. for example:

Sheet1.Activate
For CounterNumber1 = 1 To 10
For CounterNumber2 = 1 To 10
OriginalMatrix(CounterNumber1, CounterNumber2) =
Sheet1.Cells(CounterNumber1, CounterNumber2).Value
Next CounterNumber2
Next CounterNumber1

is there a way to tranfer the entire range a1 to j10 to the array at a time
so that computation becomes faster. the following code doesn't work:

Sheet1.Activate
OriginalMatrix = Sheet1.Range("a1:j10").value

any suggestions please?

tia

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Transfer data from worksheet to array

You can use a variant to pick up the data in one go:

Sub aBC()
Dim v As Variant
Dim i As Long, j As Long
' Pick it up
v = Range("A1:Z15").Value
MsgBox "v is an array of 2 dimensions " & _
vbNewLine & _
"(1 to " & UBound(v, 1) & ", 1 to " & _
UBound(v, 2) & ")"

' Process it
For i = 1 To UBound(v, 1)
For j = 1 To UBound(v, 2)
v(i, j) = Int(Rnd() * i * j + 1)
Next
Next

'Put it down
Worksheets.Add After:=Worksheets( _
Worksheets.Count)
ActiveSheet.Range("B9").Resize(UBound(v, 1), _
UBound(v, 2)).Value = v


End Sub

--
Regards,
Tom Ogilvy



"Ken Puls" wrote:

So far as I am aware, you must read your data into the array as you are
doing. Placing it back to the worksheet can be done in one step though.

Ken Puls, CMA - Microsoft MVP (Excel)
www.excelguru.ca

Pradip Jain wrote:
i need to transfer data from excel worksheet to an array. one way to do is
read cell by cell. this works fine but is very time consuming. for example:

Sheet1.Activate
For CounterNumber1 = 1 To 10
For CounterNumber2 = 1 To 10
OriginalMatrix(CounterNumber1, CounterNumber2) =
Sheet1.Cells(CounterNumber1, CounterNumber2).Value
Next CounterNumber2
Next CounterNumber1

is there a way to tranfer the entire range a1 to j10 to the array at a time
so that computation becomes faster. the following code doesn't work:

Sheet1.Activate
OriginalMatrix = Sheet1.Range("a1:j10").value

any suggestions please?

tia


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Transfer data from worksheet to array

Cheers, Tom. Thanks for the correction!

Ken Puls, CMA - Microsoft MVP (Excel)
www.excelguru.ca

Tom Ogilvy wrote:
You can use a variant to pick up the data in one go:

Sub aBC()
Dim v As Variant
Dim i As Long, j As Long
' Pick it up
v = Range("A1:Z15").Value
MsgBox "v is an array of 2 dimensions " & _
vbNewLine & _
"(1 to " & UBound(v, 1) & ", 1 to " & _
UBound(v, 2) & ")"

' Process it
For i = 1 To UBound(v, 1)
For j = 1 To UBound(v, 2)
v(i, j) = Int(Rnd() * i * j + 1)
Next
Next

'Put it down
Worksheets.Add After:=Worksheets( _
Worksheets.Count)
ActiveSheet.Range("B9").Resize(UBound(v, 1), _
UBound(v, 2)).Value = v


End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default Transfer data from worksheet to array

Hard to believe that Ken Puls is a Microsoft MVP.

Dim OriginalArray() As Variant
OriginalArray = Sheets("Sheet1").Range("A1:J10")

Alan Beban

Ken Puls wrote:
So far as I am aware, you must read your data into the array as you are
doing. Placing it back to the worksheet can be done in one step though.

Ken Puls, CMA - Microsoft MVP (Excel)
www.excelguru.ca

Pradip Jain wrote:
i need to transfer data from excel worksheet to an array. one way to
do is read cell by cell. this works fine but is very time consuming.
for example:

Sheet1.Activate
For CounterNumber1 = 1 To 10
For CounterNumber2 = 1 To 10
OriginalMatrix(CounterNumber1, CounterNumber2) =
Sheet1.Cells(CounterNumber1, CounterNumber2).Value
Next CounterNumber2
Next CounterNumber1

is there a way to tranfer the entire range a1 to j10 to the array at a
time so that computation becomes faster. the following code doesn't work:

Sheet1.Activate
OriginalMatrix = Sheet1.Range("a1:j10").value

any suggestions please?

tia



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Transfer data from worksheet to array

Just some added info (for those still using xl5 to xl97)

A variant is always successful.

support for a variant array as Alan shows was added in VBA 6/xl2000 and
later.


--
Regards,
Tom Ogilvy


"Alan Beban" wrote:

Hard to believe that Ken Puls is a Microsoft MVP.

Dim OriginalArray() As Variant
OriginalArray = Sheets("Sheet1").Range("A1:J10")

Alan Beban

Ken Puls wrote:
So far as I am aware, you must read your data into the array as you are
doing. Placing it back to the worksheet can be done in one step though.

Ken Puls, CMA - Microsoft MVP (Excel)
www.excelguru.ca

Pradip Jain wrote:
i need to transfer data from excel worksheet to an array. one way to
do is read cell by cell. this works fine but is very time consuming.
for example:

Sheet1.Activate
For CounterNumber1 = 1 To 10
For CounterNumber2 = 1 To 10
OriginalMatrix(CounterNumber1, CounterNumber2) =
Sheet1.Cells(CounterNumber1, CounterNumber2).Value
Next CounterNumber2
Next CounterNumber1

is there a way to tranfer the entire range a1 to j10 to the array at a
time so that computation becomes faster. the following code doesn't work:

Sheet1.Activate
OriginalMatrix = Sheet1.Range("a1:j10").value

any suggestions please?

tia


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Transfer data from worksheet to array

Well, your own example is not all that time-consuming -- after all, you
typed it out for this post, and it is only 5 lines.

But your second example is a little confused. If "OriginalMatrix" is
DIM'd as a matrix of variants, then it can't work. If it is DIM'd as a
Range, then you should have written:

Set OriginalMatrix = Sheet1.Range("A1:J10")

Notice there is no ".Value" property at the end. But of course, in
this second example, you should just stick with the original Range
anyway.

In short, I don't think it can get much faster.

Hope this helps (but I don't think it does),
Dom



Pradip Jain wrote:
i need to transfer data from excel worksheet to an array. one way to do is
read cell by cell. this works fine but is very time consuming. for example:

Sheet1.Activate
For CounterNumber1 = 1 To 10
For CounterNumber2 = 1 To 10
OriginalMatrix(CounterNumber1, CounterNumber2) =
Sheet1.Cells(CounterNumber1, CounterNumber2).Value
Next CounterNumber2
Next CounterNumber1

is there a way to tranfer the entire range a1 to j10 to the array at a time
so that computation becomes faster. the following code doesn't work:

Sheet1.Activate
OriginalMatrix = Sheet1.Range("a1:j10").value

any suggestions please?

tia


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
transfer data from worksheet to another dave Excel Discussion (Misc queries) 1 September 4th 08 06:14 AM
Excel Worksheet transfer of Data MaggieB New Users to Excel 2 July 23rd 07 04:38 PM
Transfer and save data from one worksheet to another. arepemko Excel Discussion (Misc queries) 2 August 30th 06 03:17 PM
Transfer data from one worksheet to another CheriT63 Excel Programming 1 April 5th 06 03:17 AM
Automatic transfer of data from one worksheet to another Lewis Shanks Excel Discussion (Misc queries) 1 January 11th 06 10:43 PM


All times are GMT +1. The time now is 03:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"