View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default array filling: cell addresses

Option Explicit

Sub test()
Dim cell As Range
Dim CellAdresses() As Variant
Dim i as Long
Redim cellAdresses(1 to selection.Count)
i = 0
For Each cell In Selection
i = i + 1
CellAdresses(i) = cell.Address
Next cell
End Sub


--
Regards,
Tom Ogilvy

"Peter" wrote in message
...
Hello everybody,

I'm trying to fill an array with the cell addresses of several separately
selected cells.

This is what I have so far:

.......
Option Explicit

Sub test()
Dim cell As Range
Dim CellAdresses() As Variant
For Each cell In Selection
CellAdresses(cell) = cell.Address
Next cell
End Sub
.....

Doing this gets me error number 9 Subscript out of range.

It's propably a simple thing I'm overlooking. Please help.

Peter.