ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Load selection into an Array - VBA (https://www.excelbanter.com/excel-programming/412086-load-selection-into-array-vba.html)

brittonsm

Load selection into an Array - VBA
 
How do I take a selection of cells on the sheet and load them into an
Array in VBA?

-Steve

RB Smissaert

Load selection into an Array - VBA
 
Dim arr

arr = Range(Cells(1), Cells(10, 10))


RBS


"brittonsm" wrote in message
...
How do I take a selection of cells on the sheet and load them into an
Array in VBA?

-Steve



JE McGimpsey

Load selection into an Array - VBA
 
One way:

Dim vArr As Variant

vArr = Range("A1:J10").Value

which loads the values in the range into a (1 To 10, 1 to 10) variant
array.



In article
,
brittonsm wrote:

How do I take a selection of cells on the sheet and load them into an
Array in VBA?

-Steve


Alan Beban[_2_]

Load selection into an Array - VBA
 
brittonsm wrote:
How do I take a selection of cells on the sheet and load them into an
Array in VBA?

-Steve

You've received two valid answers for a Variant() array or an array
contained within a Variant variable. If that is not your situation, post
back.

Alan Beban

Gary''s Student

Load selection into an Array - VBA
 
In the worst case, if your selection is a pile on non-contiguous cells, then:

Sub sel_to_array()
Dim ar() As Variant
ReDim ar(1 To Selection.Count) As Variant
i = 1
For Each r In Selection
ar(i) = r.Value
i = i + 1
Next
End Sub
--
Gary''s Student - gsnu2007j


"brittonsm" wrote:

How do I take a selection of cells on the sheet and load them into an
Array in VBA?

-Steve



All times are GMT +1. The time now is 07:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com