Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Selecting a Cell in the Current Row.

Selecting a Cell in the Current Row

by Allen Wyatt
(last updated June 3, 2015)

18

If you are developing Excel macros, you may wonder how you can select a cell relative to the one in which you are located. For instance, if you are using Excel and you press the Home key, the cell at the left side of the current row is selected. Unfortunately, using the macro recorder to record this does not help in this situation, since it records destination of the action, instead of the your actual action. For instance, if you press Home and you are on the fourth row in a worksheet, Excel doesn't record the Home action, but instead records the destination, as follows:

Range("A4").Select

This is great if you always want to go to cell A4, but terrible if you want to go to the first cell of whatever row you are on.

As with many tasks in VBA, there are several ways you can approach a solution to this dilemma. The first method is actually a variation on what the macro recorder returns, as shown above. All you need to do is change the row designator so it represents the current row, as in the following:

Range("A" & (ActiveCell.Row)).Select

VBA figures out what the current row is, slaps it together with the "A" designator, and comes up with a cell reference that works with the Range method.

Another technique you can use is to put the Cells property to work, as follows:

Cells(Application.ActiveCell.Row, 1).Select

This approach, of course, can be modified so that you actually select any given cell in the current row. All you need to do is change the column designation (1, in the above example) to a number representing the column desired.

Another approach (which produces the same result) is to use the Range object in conjunction with the Cells property, as shown here:

Range(Cells(Selection.Row, 1).Address).Select

Selection.Row gives the row number of the current selection. The Address property of the Cells method returns the address of a particular cell in A$1$ format. This address is then used as the parameter for the Range object, and the actual cell is selected by the Select method.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2267) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Selecting a Cell in the Current Row.

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

Converting Cells to Proper Case

When storing text in a worksheet, you may have a need to change the case of that text so that the initial letter in each work ...

Discover More

Two Page Numbers per Physical Page

Want to save paper when printing your document? Just print two pages per sheet of paper and you'll get rid of only half as ...

Discover More

Freezing a Table

Tired of Word changing the dimensions of table cells to accommodate what you place in those cells? You can instruct Word to ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

MORE EXCELTIPS (MENU)

Understanding Phantom Macros

When you delete all the macros in a workbook, Excel may still think you have some there. Here's why that happens and what you ...

Discover More

Disabled Macros

Do your macros seem to be disabled on your new machine? It could be because of the security settings in Excel. Here's where ...

Discover More

Using Message Boxes

When creating a macro, one of the ways you can communicate with users is through the use of a message box. This tip explains ...

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 for this tip:

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. 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 3 - 0?

2016-10-08 20:40:02

Jeff

And to apply =(1- cellvalue) to a range of cells

Thanks for any help


2016-10-08 20:03:02

Jeff

I am trying to have a macro
=(1-valueincell)

e.g. =(1-0.12%)


2016-09-22 12:46:50

Kevin M.

If you just want a straight up copy of the cell you click on to appear in another cell (O6 for my example) just past in this code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("O6").Value = ActiveCell
End Sub


2016-07-28 03:33:29

Bhagyashree

How do i select and paste only the first line of a content in a cell .. Example.. the name line from the entire address .. Or jus the telpehone number as the last line from the address. in Excel


2016-04-25 08:34:00

jimmy

if i have a large data. how to sort according with different row?? how to use erow on colomn 4


2016-03-11 15:30:05

ken dupont

I need to copy cells A1, B1, C1,D1 to a different sheet F5,G5, H5, I5 . This is easy but Range(A1:D1) changes with new info. If I copy using a macro i need the macro to move old data down 1 row and paste special value into the Range(F6:I6). The Macro now places the new data into Range(A1:D1) moving it to Range(F5:I5). Here comes the problem. I now need to move the first 2 data sets down 1 row so new transferred data wont over write the top row


2015-12-17 09:56:43

Music

Is there an easy way to get a cell in the current column?
As you know Activecell.column gets you a number and not the letter.


2015-03-08 06:09:14

Michael (Micky) Avidan

@JMJ,
NP - but please note that this request was to refer(!) to that cell (meaning, to know it's address and probably not for selecting it).
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL


2015-03-07 12:30:30

JMJ

Sorry Micky, I didn't see you answer before posting :-[


2015-03-07 12:28:58

JMJ

@Ivor Shaer:

Something as
Selection.Offset(0, 2).End(xlUp).Select
should do the trick.

Hope this helps


2015-03-07 05:51:25

Michael (Micky) Avidan

@Ivor,
In order to return the expected cell's address - try:
MsgBox Selection.Offset(0, 2).End(xlUp).Address
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL


2015-03-06 21:04:08

Ivor Shaer

I need to reference, not select, the first used cell above a specified cell as follows
"First used cell above(Selection.offset(0,2)

Is this possible?

Thanks.
Ivor


2013-08-19 20:44:38

Adolfo Vazquez

Mr. Wyatt, your solution to get the first cell in a row starting from any of same row was an issue I had tried to solve for long time without success. Till now with you. Thanks a lot.


2013-07-22 13:55:21

joseph

How I Clear Some cello content current row vba


2013-03-11 20:30:09

Aadesh

Hello,
I am trying to get to the first row of the coloumn I am in, I tried modyfying the formual you have Cells(Application.ActiveCell.Row, 1).Select

but was not able to get it to work.
What I eventually want to get to is this, for any cell in the column when I run the macro it should give me product of first cell in the coloumn and third cell in the column, something like this (=C3*$C$1). Also the first cell should be fixed.


2012-11-02 10:51:52

VideoFlyer

Using the same methodology, a formula can also include "ActiveCell.Row". Once in the cell you want to put the formula, be it manually, or with a macro, a simple format would be:

ActiveCell.Formula = "=A" & ActiveCell.Row


2012-02-18 09:25:40

jmj

Another simple solution is to use a named cell (or field) and then you can use:
[name].select
Neat, no?


2012-02-14 08:14:32

Dave Roberts

I'm sorry for the question versus a comment. You use activecell.row with range and application.activecell.row with cells. I tried with and without application. Does it make a difference? Thanks.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.

Links and Sharing