Excel automation – Select all active cells

calendar_today Asked Apr 30, 2009
thumb_up 12 upvotes
history Updated April 16, 2026

Question posted 2009 · +2 upvotes

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 3×3 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)

Accepted answer +12 upvotes

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

2 code variants in this answer

  • Variant 1 — 3 lines, starts with Range("A1").Select
  • Variant 2 — 5 lines, starts with Range("C6").Select ' Select a cell that you know you popul…

Excel VBA objects referenced (5)

  • Range — Refer to Cells by Using a Range Object
  • Range — Delete Duplicate Entries in a Range
  • Selection — Working with the Selection Object
  • Worksheet — Refer to All the Cells on the Worksheet
  • Worksheet — List of worksheet functions available to Visual Basic

Top excel-vba Q&A (6)

+12 upvotes ranks this answer #45 out of 136 excel-vba solutions on this site .