Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Efficiently moving data between worksheets and VBA array variables

I need to move data to and from a worksheet quickly.

The first code segment efficiently moves data from a VBA array to the
worksheet. However, going the other way, the second code doesn't work
transfering from the sheet to the VBA array.

Why doesn't the second example work? Is there an efficient way to transfer
data without stepping through a loop?


This works:
'Transfer the array to the worksheet starting at cell A2
Dim DATAaRRAY(1 To 100, 1 To 3) As Variant
mySheet.Range("A2").Resize(100, 3).Value = DATAaRRAY

This doesn't work:
'Transfer from the worksheet to the Array doesn't work.
Dim DATAaRRAY(1 To 100, 1 To 3) As Variant
DATAaRRAY = mySheet.Range("A2").Resize(100, 3).Value

Thanks in advance.
Fred.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Efficiently moving data between worksheets and VBA array variables

Try declaring DataArray like:
Dim DATAaRRAY As Variant
dataarray = mysheet.range("a2").resize(100,3).value



Fred wrote:

I need to move data to and from a worksheet quickly.

The first code segment efficiently moves data from a VBA array to the
worksheet. However, going the other way, the second code doesn't work
transfering from the sheet to the VBA array.

Why doesn't the second example work? Is there an efficient way to transfer
data without stepping through a loop?

This works:
'Transfer the array to the worksheet starting at cell A2
Dim DATAaRRAY(1 To 100, 1 To 3) As Variant
mySheet.Range("A2").Resize(100, 3).Value = DATAaRRAY

This doesn't work:
'Transfer from the worksheet to the Array doesn't work.
Dim DATAaRRAY(1 To 100, 1 To 3) As Variant
DATAaRRAY = mySheet.Range("A2").Resize(100, 3).Value

Thanks in advance.
Fred.


--

Dave Peterson
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 efficiently declare variables Jeff Excel Discussion (Misc queries) 2 June 29th 06 01:56 PM
efficiently copy values from a Range of cells to an array (in VB.N JW Excel Programming 0 June 22nd 04 11:17 AM
efficiently copy values from a Range of cells to an array (in VB.N JW Excel Programming 0 June 22nd 04 11:15 AM
Efficiently transform variables into range address Charles Williams Excel Programming 0 May 3rd 04 06:32 PM
Efficiently transform variables into range address Frank Kabel Excel Programming 0 May 3rd 04 04:10 PM


All times are GMT +1. The time now is 10:27 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"