Written by Allen Wyatt (last updated April 6, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
If you need to select the first cell in a row from within your macro, you can do it with the Select method, as follows:
Cells(ActiveWindow.RangeSelection.Row, 1).Select
Once executed, the selected cell becomes the first cell (in column A) of the current row. If you run this line while a range of cells is selected, then the cell in column A of the first row of the selection is selected.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7602) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Selecting the First Cell In a Row.
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!
It is not uncommon to set variables in a macro based on other values, such as time or date. You could also set variables ...
Discover MoreNeed to run a DOS command from within one of your macros? The answer is the Shell command, described in this tip.
Discover MoreWhen you add a new worksheet to a workbook, Excel gives it a default name that consists of "Sheet" followed by a number. ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-04-07 04:36:30
Rick Rothstein
@RKeev,
You changed the problem from the one Allen proposed. He wanted the selection to move to Column A on the same row as the ActiveCell whereas your code selects the next (downward) visible cell within the same column as the ActiveCell. Given that, your function does not need to be that "complex"... you can do what your code does with a single line of code...
Range(ActiveCell.Offset(1), Cells(Rows.Count, ActiveCell.Column)).SpecialCells(xlVisible)(1).Select
2022-04-06 09:46:52
RKeev
What if there are hidden rows?
This selects the next visible cell from the active cell
Sub NextVisible()
Dim r As Range
Set r = ActiveCell
For i = 1 To Rows.Count
Set r = r.Offset(1, 0)
If r.EntireRow.Hidden = False Then
r.Select
Exit Sub
End If
Next
End Sub
2022-04-06 04:32:11
Rick Rothstein
Another way to do this...
ActiveCell.EntireRow.Cells(1).Select
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments