ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   load addresses of selected cells into array (https://www.excelbanter.com/excel-programming/360129-load-addresses-selected-cells-into-array.html)

galefly

load addresses of selected cells into array
 
I want to physically select non-adjacent rows (alt-left button) in a
worksheet and load the adresses into an array...

example: select "a1", "b6", "c4" and end up with an array:

1 1
6 2
4 3

thanks for any help


galefly

load addresses of selected cells into array
 
I did not mean "ROWS", I meant to to say "CELLS)
thanks, galefly


Tom Ogilvy

load addresses of selected cells into array
 
Dim v as Variant, i as Long
redim v(1 to selection.count, 1 to 2)
i = 1
for each cell in selectin
v(i,1) = cell.Row
v(i,2) = cell.column
i = i + 1
Next

--
Regards,
Tom Ogilvy

"galefly" wrote in message
oups.com...
I did not mean "ROWS", I meant to to say "CELLS)
thanks, galefly




galefly

load addresses of selected cells into array
 
Tom,

thanks.. it bombed on CELL, "variable not defined"


Dave Peterson

load addresses of selected cells into array
 
Option Explicit
Sub testme()
Dim v As Variant, i As Long
Dim cell As Range
ReDim v(1 To Selection.Count, 1 To 2)
i = 1
For Each cell In Selection
v(i, 1) = cell.Row
v(i, 2) = cell.Column
i = i + 1
Next
End Sub

galefly wrote:

Tom,

thanks.. it bombed on CELL, "variable not defined"


--

Dave Peterson

Tom Ogilvy

load addresses of selected cells into array
 
Dim v as Variant, i as Long
Dim cell as Range ' <==
redim v(1 to selection.count, 1 to 2)
i = 1
for each cell in selection '<== selection misspelled
v(i,1) = cell.Row
v(i,2) = cell.column
i = i + 1
Next

--
Regards,
Tom Ogilvy

"galefly" wrote in message
oups.com...
Tom,

thanks.. it bombed on CELL, "variable not defined"




galefly

load addresses of selected cells into array
 
Thanks guys... I caught the spelling error and changed it but still had
the problem... I surely managed to accidently slip and mess up
something else in that tiny snippet of code..It works like a charm. I
have done a lot of VBA programming (mosty ACCESS) but very little in
EXCEL. I am having a bit of a problem getting a handle on the objects..
There seems to be 80 ways to do anything.



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

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