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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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
 
Upvote 0
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
 
Upvote 0
That's exactly what I needed...Thanks!

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

Forum statistics

Threads
1,213,489
Messages
6,113,949
Members
448,534
Latest member
benefuexx

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
Back
Top