Selecting to the Bottom of a Column in a Macro

Written by Allen Wyatt (last updated January 2, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


2

Ian has a macro in which he needs to select a range of cells, from the fifth row of a column to the last value in the column. There may be blank cells in the range, but Ian needs to select everything through whatever the last-used cell is in the column.

Selecting the last used cell in a column is fairly straightforward—you use the .End method to locate the cell. For instance, you could use the following single line to select the desired range in column A, from A5 (the fifth row, as Ian indicated) through the last-used cell:
Range("A5",Range("A" & Rows.Count).End(xlUp)).Select
The .Count property when used with the Rows collection returns a numeric value for the total number of rows in the worksheet. Taking it one step further and applying the .End method specifies that the returned range should be just the last-used cell in the column. Note that the macro line assumes you want to select the cells in column A. It is very possible, of course, that you might want to select cells in a different column. The best way to accommodate that is to simply make sure that the "A" portion of the macro is a variable:
sColWanted = "A"
Range(sColWanted & "5",Range(sColWanted & Rows.Count).End(xlUp)).Select
You could even wrap the lines in a subroutine that could then be called from another macro:
Sub SelectCells(sCol As String)
    Range(sCol & "5",Range(sCol & Rows.Count).End(xlUp)).Select
End Sub

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13818) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Using the XIRR Function

One of the financial worksheet functions provided in Excel is the XIRR function. This is used to figure out an internal ...

Discover More

Extracting Targeted Records from a List

If you have a bunch of data in an Excel worksheet, you may need to work with just a subset of that data. One way to do ...

Discover More

Turning Off a Startup Sound

If you hear a sound when you start Word, it is because of some settings within Windows itself. You can use the Control ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Recording a Macro

One of the most common ways of creating macros is to use Excel's macro recorder. This tip shows how easy it is to use the ...

Discover More

Jumping to the Start of the Next Data Entry Row

Want a quick way to jump to the end of your data entry area in a worksheet? The macro in this tip makes quick work of the ...

Discover More

Friendly and Informative Error Handling

When creating macros, it is helpful to know what is going on within the macro itself in case an error crops up. Here's ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two less than 9?

2021-01-03 10:37:41

J. Woolley

There is a typo error in the next-to-last statement of my modified Sub SelectCells(...) below. Although
Range(sCol & "5", Range(sCol & lastRow)).Select
works as intended, it should be written more clearly as
Range(sCol & "5", sCol & lastRow).Select


2021-01-02 10:19:54

J. Woolley

The Tip's final subroutine will not select everything if the column's last-used cell is in a hidden row (by filtering, for example). This modification will:
Sub SelectCells(sCol As String)
lastRow = Columns(sCol).Find(What:="*", _
After:=Columns(sCol).Cells(1), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Range(sCol & "5", Range(sCol & lastRow)).Select
End Sub


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.