Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I want to let my user select any combination of cells, and then read the values from them into a one-dimensional array. How can I do this? Some parts of the selection may be two-dimensional, while other parts may be one-dimensional. I also need to cycle through each seperate selected area. Thanks for any help, Jamie |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You appear to be asking two unrelated questions:
1) I want to let my user select any combination of cells, and then read the values from them into a one-dimensional array. How can I do this? 2) I also need to cycle through each seperate [sic] selected area. 1) If the functions in the freely downloadable file at http://home.pacbell.net/beban are available to your workbook: Sub test1() With Selection For i = 1 To .Areas.Count arr = MakeArray(arr, .Areas(i), 1) Next End With arr = SubArray(arr, 2, UBound(arr), 1, 1) End Sub 2) Sub test2() For Each iArea In Selection.Areas For Each iCell In iArea Debug.Print iCell.Value Next Next End Sub Alan Beban Jamie Martin wrote: Hi, I want to let my user select any combination of cells, and then read the values from them into a one-dimensional array. How can I do this? Some parts of the selection may be two-dimensional, while other parts may be one-dimensional. I also need to cycle through each seperate selected area. Thanks for any help, Jamie |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Another way might be
Dim myArray() as Variant Dim rng as Range Dim i as long set rng = Selection Redim myArray(1 to rng.Count) i = 0 for each cell in rng i = i + 1 myArray(i) = cell.Value Next so as a test I filled the sheet so each cell displayed its address, selected some cells at random, then ran this: Sub Tester1() Dim myArray() As Variant Dim rng As Range Dim i As Long Set rng = Selection Debug.Print rng.Address ReDim myArray(1 To rng.Count) i = 0 For Each cell In rng i = i + 1 myArray(i) = cell.Value Debug.Print i, myArray(i) Next End Sub Which produced: $A$1,$D$8:$E$9,$C$3,$E$1,$C$13:$D$14 1 A1 2 D8 3 E8 4 D9 5 E9 6 C3 7 E1 8 C13 9 D13 10 C14 11 D14 -- Regards, Tom Ogilvy "Jamie Martin" wrote in message ... Hi, I want to let my user select any combination of cells, and then read the values from them into a one-dimensional array. How can I do this? Some parts of the selection may be two-dimensional, while other parts may be one-dimensional. I also need to cycle through each seperate selected area. Thanks for any help, Jamie |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() "Alan Beban" wrote in message ... You appear to be asking two unrelated questions: 2) I also need to cycle through each seperate [sic] selected area. ops, i forgut mi splcheck. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't have "cell" as a keyword. I need to declare it, I think . . . what
kind of object should it be? "Tom Ogilvy" wrote in message ... Another way might be Dim myArray() as Variant Dim rng as Range Dim i as long set rng = Selection Redim myArray(1 to rng.Count) i = 0 for each cell in rng i = i + 1 myArray(i) = cell.Value Next so as a test I filled the sheet so each cell displayed its address, selected some cells at random, then ran this: Sub Tester1() Dim myArray() As Variant Dim rng As Range Dim i As Long Set rng = Selection Debug.Print rng.Address ReDim myArray(1 To rng.Count) i = 0 For Each cell In rng i = i + 1 myArray(i) = cell.Value Debug.Print i, myArray(i) Next End Sub Which produced: $A$1,$D$8:$E$9,$C$3,$E$1,$C$13:$D$14 1 A1 2 D8 3 E8 4 D9 5 E9 6 C3 7 E1 8 C13 9 D13 10 C14 11 D14 -- Regards, Tom Ogilvy "Jamie Martin" wrote in message ... Hi, I want to let my user select any combination of cells, and then read the values from them into a one-dimensional array. How can I do this? Some parts of the selection may be two-dimensional, while other parts may be one-dimensional. I also need to cycle through each seperate selected area. Thanks for any help, Jamie |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try:
Dim cell As Range In article , "Jamie Martin" wrote: I don't have "cell" as a keyword. I need to declare it, I think . . . what kind of object should it be? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Array with multiple selection criteria | Excel Worksheet Functions | |||
Why the arbitrary spreadsheet size limitations? | Excel Discussion (Misc queries) | |||
Arbitrary Lookups - return ALL found values | Excel Worksheet Functions | |||
Reading formatted cell values into an array | Excel Programming | |||
Reading a cell into an array | Excel Programming |