Last cell in spreadsheet

  • Thread starter Thread starter Ritchie
  • Start date Start date
R

Ritchie

In my spreadsheet, I need to sort the data a number of
different ways. I originally used the following code:
Range("A12:L12").Select
Range(Selection, Selection.End(xlDown)).Select
to select all of the items in the spreadsheet.

Since then, I have found that columns A may not contain
data in all rows; which stops the sort at the first blank
row; even though there is data in subsequent rows.

This all so holds true for columns B, C, and D

I have tried to correct that shortcoming with something
like the following code but without much success:

Range("A12:specialcells(xlcelltypelastcell)").Select

Any suggestions would be greatly appreciated. Thanks!
 
This will return the last row that contains a value in
column A.

LastRow = ActiveSheet.Range("A65536").end(xlup).row

This is the same thing as going to cell A65536 and then
using Ctrl+Up Arrow.

So as long as the longest column of data is column A, you
could do this:

ActiveSheet.Range("A12:L" & ActiveSheet.Range("A65536").End
(xlup).Row).Select
 
Ritchie

Sub SelectActiveArea()
Range(Range("A12:L12"), ActiveCell.SpecialCells(xlLastCell)).Select
'run your Sort code
End Sub

Gord Dibben Excel MVP
 

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