Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default reading an arbitrary selection into a 1D array

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default reading an arbitrary selection into a 1D array

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default reading an arbitrary selection into a 1D array

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default reading an arbitrary selection into a 1D array


"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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default reading an arbitrary selection into a 1D array

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default reading an arbitrary selection into a 1D array

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array with multiple selection criteria Robert Robinson Excel Worksheet Functions 9 March 31st 09 01:17 AM
Why the arbitrary spreadsheet size limitations? T Magritte Excel Discussion (Misc queries) 7 July 24th 08 09:12 AM
Arbitrary Lookups - return ALL found values baki Excel Worksheet Functions 8 May 13th 08 06:23 PM
Reading formatted cell values into an array Tom Ogilvy Excel Programming 0 September 19th 03 06:32 PM
Reading a cell into an array Tick-Tock Excel Programming 2 September 11th 03 07:33 PM


All times are GMT +1. The time now is 12:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"