Storing data in an array

jbrouse

Active Member
Joined
Apr 28, 2005
Messages
329
Greetings,

I'm trying to pass information from one worksheet to another. When my sub-routine is called, it checks for which form the active sheet contains, and calls the appropriate sub-routine. In this sub-routine, all of my data to be copied is set.

Is there any way I can use an array or something similar to store all data in Cells C6:C30, D6:D30, and F6:F30, to be called on at a later time?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi jbrouse

I did not fully understand your problem so I'll just answer to:

Is there any way I can use an array or something similar to store all data in Cells C6:C30, D6:D30, and F6:F30, to be called on at a later time?

Example C6:D30 is a range with 25 rows and 2 columns. You can write an array in that range. Ex:

Code:
Option Explicit
Option Base 1

Sub ArrRngTest()
Dim arr(25, 2), i As Integer

For i = 1 To 25
    arr(i, 1) = i
    arr(i, 2) = 100 + i
Next

Range("C6:D30") = arr

End Sub

Is this what you want?
PGC
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

the other way around perhaps ?

Option Explicit

Code:
Sub use_array()
Dim rng As Range
Dim arr As Variant
Dim I As Long, J As Long

Set rng = Range("C6:D30")

arr = rng

'other code if you want
'next lines would do some operations with the array
For I = 1 To rng.Rows.Count
  For J = 1 To rng.Columns.Count
  arr(I, J) = arr(I, J) & "hello"
  Next J
Next I
'array is written back to sheet
'in this case to same range, but can be another range (needs: same dimensions)
rng = arr
End Sub
NOTE: you cannot pass a range with different areas to one array, unless you use more code ...

kind regards,
Erik
 

jbrouse

Active Member
Joined
Apr 28, 2005
Messages
329
That's exactly what I needed...Thanks!

I apologize for the confusing post It has been a long day. :unsure:
 

Forum statistics

Threads
1,136,266
Messages
5,674,727
Members
419,523
Latest member
Urnovio

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top