views:

1239

answers:

2

I have an app where I put a lot of data into an Excel Worksheet. Once I'm done, I would like to select all the cells from the top left to the bottom right where I have put data in. E.g. say I put data into A1, A2, A3, B1, B2, B3, C1, C2, C3 (a 3x3 grid). How can I select just this grid (and not the entire sheet). I guess by saying something like

ActiveSheet.SelectUsedCells

Any pointers? (Yes - I know I could just remember the bottom right cell when I put it in from my app)

+2  A: 

Here you go:

Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select

Or if you don't necessarily start at A1:

Range("C6").Select  ' Select a cell that you know you populated'
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
RichieHindle
+3  A: 

You might also want to look at the CurrentRegion property. This will select a contiguous range that is bounded by empty cells, so might be a more elegant way of doing this, depending on the format of your worksheet.

Lunatik