really simple array question

Alisa

Board Regular
Joined
Jan 28, 2005
Messages
97
I don't know why I can't figure this out - it seems like it should be so simple.
I have a range of cells selected (for instance, c1 to c5). I want the value of each cell to be an element of an array. How is this done?

Thanks for any help, Alisa
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi Alisa,


Here's one way ...


Code:
Option Explicit

Sub ArrayExample()
    Dim arr(1 To 5) As Variant, i As Long
    For i = LBound(arr) To UBound(arr)
        arr(i) = Range("C" & i).Value
    Next i
End Sub
 
Upvote 0
Here's another,

From a selection:

Code:
Sub activeArray()
Dim x()
x = Selection.Value
End Sub

or from a range specified in code:

Code:
Sub activeArray()
Dim x()
x = Range("C1:C5").Value
End Sub

This will create a two-dimensional array, first dimension is the row # and the second dimension the column #.
 
Upvote 0

Forum statistics

Threads
1,203,464
Messages
6,055,573
Members
444,799
Latest member
CraigCrowhurst

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