first and last cells of manually selected regions

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

John Smith

I'm writing a script to be run on manually selected regions in
different worksheets in the same workbook. (I'll select one region
at a time and then run the script.)

How do I programmatically find the first and last cells
(upper-left and bottom-right corners) of a manually selected
region? Thanks.
 
you can try these statements and see if they work for you

selection.range("A1").address

selection.specialcells(xlcelltypelastcell).address
 
Sub aaaa()
Dim rng As Range
Set rng = Selection.Cells
If rng.Areas.Count > 1 Then
MsgBox "multiple selection"
Else
MsgBox rng(1).Address & vbCr & rng(rng.Count).Address
End If
Set rng = Nothing
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"John Smith" <[email protected]>
wrote in message
I'm writing a script to be run on manually selected regions in
different worksheets in the same workbook. (I'll select one region
at a time and then run the script.)

How do I programmatically find the first and last cells
(upper-left and bottom-right corners) of a manually selected
region? Thanks.
 
Are they single area ranges?

with selection
msgbox .cells(1).address & vblf & .cells(.cells.count).address
end with
 

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