Select first to last row : Row « Excel « VBA / Excel / Access / Word






Select first to last row

 

Sub SelectFirstToLastInRow()
    Set LeftCell = Cells(ActiveCell.Row, 1)
    Set RightCell = Cells(ActiveCell.Row, 256)

    If IsEmpty(LeftCell) Then Set LeftCell = LeftCell.End(xlToRight)
    If IsEmpty(RightCell) Then Set RightCell = RightCell.End(xlToLeft)
    If LeftCell.Column = 256 And RightCell.Column = 1 Then ActiveCell.Select Else Range(LeftCell, RightCell).Select
End Sub

 








Related examples in the same category

1.change row height
2.Select active row
3.Clearing a range differs from deleting a range. When you delete a range, Excel shifts the remaining cells around to fill up the range you deleted.
4.Select entire row
5.Get the last row and last cell
6.Set the color row by row
7.Delete empty rows
8.Bold cells in a Row
9.Array to rows
10.Array to rows - method (Limited to 65,536)
11.Is in last row
12.returns a number that represents the last nonempty cell in the same row