Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying an array

Status
Not open for further replies.

darronb

Technical User
Feb 8, 2002
67
0
0
GB
I am trying to copy an array into another array.

I am using Excel 97 and writing a macro to do this. I have an array "NorthArray(100,19)" and I am trying to copy it to "TotalArray(100,19)".

The line I used was

NorthArray(100,19) = TotalArray(100,19)

This did not work

I have defined both of these

Dim NorthArray(100, 19) As String
Dim TotalArray(100, 19) As String

I am a novice at this, can anyone help.

Thanks


 


Hi,
Code:
for i = lbound(NorthArray, 2) to ubound(NorthArray, 2)
for j = lbound(NorthArray, 1) to ubound(NorthArray, 1)
NorthArray(j,i) = TotalArray(j,i)
next
next


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 



gotta SWITCH...
Code:
for i = lbound(NorthArray, 2) to ubound(NorthArray, 2)
for j = lbound(NorthArray, 1) to ubound(NorthArray, 1)
TotalArray(j,i) = NorthArray(j,i)
next
next


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
this works for me:

Dim firstArr As Variant
Dim SecondArr As Variant

Set firstArr = Range("A1:E10")
Set SecondArr = firstArr

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Thanks SkipVought that has worked a treat
 

You can't assign to a fixed array so if you have them both defined as you show then you must use Skip's method. But if you define the receiving array as dynamic (or as variant as Geoff has done) then you can do it in a single statement ..
Code:
Dim NorthArray(100, 19) As String
Dim TotalArray() As String
NorthArray(3, 0) = "sample"
NorthArray(0, 1) = "something"
NorthArray(8, 3) = "or other"
NorthArray(88, 18) = "just to"
NorthArray(41, 19) = "illustrate"
TotalArray = NorthArray

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top