05-16-2008, 02:14 AM
If the user selects a range in excel, how can I determine the first and the last row or column of the selected cells?
The Application returns a Selection object that's set to the selected range, if any. To get information about its size, you use the usual range properties:
Public Sub printSelection()
Dim thisSelection As Range: Set thisSelection = Application.Selection
You should include some error handling code, because Selection can return other things than a range as well, if other things than cells are currently selected.
05-16-2008, 05:37 AM
Thanks for the quick reply.
But what if the user selects multiple ranges? (A1 to A4 and A10 to A20)
How can I detect multiple ranges?
05-16-2008, 05:43 AM
Look up the Range Object's Areas Property and also Areas Collection (for example code) in your Excel VBA helpfile.