Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

noob needs help with arrays

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
this is most likely a very simple question as im very new to vba but

im trying to get the data into an array via an input box in which the user selects the range of cells with the relevant data.

example:
Dim grouprange As Range

Set grouprange() = Application.InputBox _
(prompt:="please select the grouping you wish to use", Type:=8)

any help as to how i can do this (or maybe an easier way using refedit boxes...) would be most appreciated
 
k3ys3r,

it's not an array, it is a range object;

Dim groupRange As Range
Set groupRange = Application.InputBox _
(prompt:="please select the grouping you wish to use", Type:=8)

MsgBox groupRange.Address + " on " + groupRange.Worksheet.Name

ide
 
The fastest way to transfer data from a spreadsheet range to an array is by using this VBA command:

myArray = Range("someRange").value

To apply this to your situation, place the numbers 1 through 4 in cells A1:D1, and run the following routine:

Sub TransferToArray()
Dim groupRange
groupRange = Application.InputBox _
(prompt:="please select the grouping you wish to use", Type:=8).Value
For t = 1 To UBound(groupRange, 2)
MsgBox groupRange(1, t)
Next
End Sub

Notice that the groupRange assignment is exactly like the first example. Because you're the result of this InputBox selection is a range, use the .Value and assign it to the variable.

You now have an array with 1 row and 4 columns. I hard-wired this for the example, but there's really no need to.

Hope this helps,

Stan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top