Getting Selected

  • Thread starter Thread starter John
  • Start date Start date
J

John

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
 
John said:
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.Count-1,
Selection.Column+Selection.Columns.Count-1).AddressLocal

Iain King
 
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.
 
oops, not quite finished :)
strTopLeft = Activesheet.Cells(Selection.Row, Selection.Column).AddressLocal
strBottomRight = Activesheet.Cells(Selection.Row+Selection.Rows.Count-1, _
Selection.Column+Selection.Columns.Count-1).AddressLocal

strSelectedRange = strTopLeft+":"+strBottomRight

Iain King
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top