Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default copy 1 array to another array

Is there a function in VBA that will allow me to copy from 1 array to
another. I know that I can loop throught each element and assign 1 array to
the other. But I want to know if there's a faster way such array1 = array2.
Assume they both have the same size.

Thanks
M
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default copy 1 array to another array

Hi,

This works if it helps (you cannot assign to an array):

Sub a()

Dim array1(10, 10), array2() As Variant

For i = 1 To 10
For j = 1 To 10
array1(i, j) = i ^ j
Next j
Next i

array2 = array1

For i = 1 To 10
For j = 1 To 10
Debug.Print array2(i, j)
Next j
Next i
End Sub

"matelot" wrote:

Is there a function in VBA that will allow me to copy from 1 array to
another. I know that I can loop throught each element and assign 1 array to
the other. But I want to know if there's a faster way such array1 = array2.
Assume they both have the same size.

Thanks
M

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default copy 1 array to another array

With VB6 (XL2000 or later), use array1=array2, though the target array
cannot be dimensioned.

Option Explicit
Option Base 0

Sub testArrays()
Dim Arr1(2), Arr2()
Arr1(0) = 1: Arr1(1) = 2: Arr1(2) = 3
Arr2 = Arr1
MsgBox Arr2(2)
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Is there a function in VBA that will allow me to copy from 1 array to
another. I know that I can loop throught each element and assign 1 array to
the other. But I want to know if there's a faster way such array1 = array2.
Assume they both have the same size.

Thanks
M

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default copy 1 array to another array

Just to add, for all versions incl. XL97 declare the target variable as a
non-array variant. In Tushar's demo change -

Dim Arr1(2), Arr2()

to
Dim Arr1(2), Arr2

Regards,
Peter T


"Tushar Mehta" wrote in message
om...
With VB6 (XL2000 or later), use array1=array2, though the target array
cannot be dimensioned.

Option Explicit
Option Base 0

Sub testArrays()
Dim Arr1(2), Arr2()
Arr1(0) = 1: Arr1(1) = 2: Arr1(2) = 3
Arr2 = Arr1
MsgBox Arr2(2)
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Is there a function in VBA that will allow me to copy from 1 array to
another. I know that I can loop throught each element and assign 1 array

to
the other. But I want to know if there's a faster way such array1 =

array2.
Assume they both have the same size.

Thanks
M



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default copy 1 array to another array

Thanks for the response. That's what I need it.
BTW, what is the i^j? Is it supposed to be i power to j?

"Peter T" wrote:

Just to add, for all versions incl. XL97 declare the target variable as a
non-array variant. In Tushar's demo change -

Dim Arr1(2), Arr2()

to
Dim Arr1(2), Arr2

Regards,
Peter T


"Tushar Mehta" wrote in message
om...
With VB6 (XL2000 or later), use array1=array2, though the target array
cannot be dimensioned.

Option Explicit
Option Base 0

Sub testArrays()
Dim Arr1(2), Arr2()
Arr1(0) = 1: Arr1(1) = 2: Arr1(2) = 3
Arr2 = Arr1
MsgBox Arr2(2)
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Is there a function in VBA that will allow me to copy from 1 array to
another. I know that I can loop throught each element and assign 1 array

to
the other. But I want to know if there's a faster way such array1 =

array2.
Assume they both have the same size.

Thanks
M




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
Prevent cell/array references from changing when altering/moving thecell/array nme Excel Discussion (Misc queries) 1 September 19th 08 01:53 PM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
Copy Array pointer rather than entire array R Avery Excel Programming 2 August 24th 04 08:28 PM


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