Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the topleft and bottomright cell from a selection 1

Status
Not open for further replies.

boggg1

Programmer
Oct 17, 2002
102
EU
I have a program which analyses a section of Excel data using automation to acquire the data from an Excel worksheet. Currently the limits of the data are the top left cell of the sheet (A1) and a cell defined in two text boxes txtNoColumns and txtNoRows. I then use a For...Next loop to iterate through the data (eg For Column = 1 to txtNoColumns). I would like to extend the capabilities to allow the user to select the region to be analysed by highlighting the data on the Excel spreadsheet, rather than using the text boxes. How do I get the top left and bottom right cells from the .Selection so that I can continue to use the For...Next method.

This must be easy !

Thanks,
Boggg1
[bigglasses]
 
You can take a look at the Address property of the Range object.
You may also consider a For Each myCell In Application.Selection loop.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Address property of selection that's it !
Selection.address

Thanks.

Your other solution is quite right but it is exactly what I wanted to avoid because it will mean much code changing !

Boggg1
[bigglasses]
 
Address property of selection that's it !
Selection.address

Thanks.

Your other solution is quite right but it is exactly what I wanted to avoid because it will mean much code changing ! I may return to it if manipulating the address proves too obscure.

Have a star.

Boggg1
[bigglasses]
 
Selection.Address is now working in my code. Thanks again.

Boggg1
[bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top