ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting Selected (https://www.excelbanter.com/excel-programming/309125-getting-selected.html)

John[_94_]

Getting Selected
 
If macro starts with a selected area (by mouse) how do you get the
corner cells of the selected area? In other words obtain the cell:cell form.

Thanks


Iain King

Getting Selected
 

"John" wrote in message
...
If macro starts with a selected area (by mouse) how do you get the
corner cells of the selected area? In other words obtain the cell:cell

form.

Thanks


you need to use the AddressLocal property of the selected Range. So:

strTopLeft = Activesheet.Cells(Selection.Row, Selection.Column).AddressLocal
strBottomRight = Activesheet.Cells(Selection.Row+Selection.Rows.Cou nt-1,
Selection.Column+Selection.Columns.Count-1).AddressLocal

Iain King



Dave Peterson[_3_]

Getting Selected
 
dim myRng as range
set myRng = selection.areas(1)

msgbox myrng.cells(1).address
msgbox myrng.cells(myrng.cells.count).address


I used Areas(1) just in case you have more than one area selected.


John wrote:

If macro starts with a selected area (by mouse) how do you get the
corner cells of the selected area? In other words obtain the cell:cell form.

Thanks


--

Dave Peterson


Iain King

Getting Selected
 
oops, not quite finished :)

strTopLeft = Activesheet.Cells(Selection.Row,

Selection.Column).AddressLocal
strBottomRight = Activesheet.Cells(Selection.Row+Selection.Rows.Cou nt-1, _
Selection.Column+Selection.Columns.Count-1).AddressLocal


strSelectedRange = strTopLeft+":"+strBottomRight

Iain King



Tom Ogilvy

Getting Selected
 
for a single area:

msgbox Selection.Address(0,0)

--
Regards,
Tom Ogilvy


"John" wrote in message
...
If macro starts with a selected area (by mouse) how do you get the
corner cells of the selected area? In other words obtain the cell:cell

form.

Thanks





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

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