Put rage of cells in an array

nikko50

Board Regular
Hi all!

So I need to build an array with values from a couple sets of cell ranges. I need to grab the values from row 2 Cell B - Cell E and row 2 Cell J - Cell AO. How can I do that?

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Domenic

MrExcel MVP
Assuming that the active sheet contains the data, the following macro fills an array with values from the two specified ranges, creates a new worksheet, and transfers the contents of the array to the new worksheet in Column A, starting at A2...

Code:
``````[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit[/COLOR]

[COLOR=darkblue]Sub[/COLOR] test()

[COLOR=darkblue]Dim[/COLOR] rData [COLOR=darkblue]As[/COLOR] Range
[COLOR=darkblue]Dim[/COLOR] rCell [COLOR=darkblue]As[/COLOR] Range
[COLOR=darkblue]Dim[/COLOR] Indx [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]

[COLOR=darkblue]Set[/COLOR] rData = Union(Range("B2:E2"), Range("J2:AO2"))

[COLOR=darkblue]ReDim[/COLOR] aData(1 [COLOR=darkblue]To[/COLOR] rData.Cells.Count, 1 [COLOR=darkblue]To[/COLOR] 1)

Indx = 1
[COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] rCell [COLOR=darkblue]In[/COLOR] rData.Cells
Indx = Indx + 1
[COLOR=darkblue]Next[/COLOR] rCell

[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]``````

Hope this helps!

Replies
3
Views
34
Replies
0
Views
71
Replies
1
Views
164
Replies
1
Views
78
Replies
2
Views
63

1,195,855
Messages
6,011,973
Members
441,658
Latest member
Carlos O

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.

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

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