How to select the lastrow

前端 未结 2 1412
后悔当初
后悔当初 2021-01-29 04:13

I have an excel sheet it contains data as below:

    A      B      C     D     E      F           
1   10     11     12    78    45

2   12     15     15    78           


        
2条回答
  •  不要未来只要你来
    2021-01-29 04:24

    To Select the last row with data, first move upwards from the bottom to find the row and then move leftwards on that row to find that last used column:

    Sub SelectLastRow()
        Dim nRow As Long, nColumn As Long
        nRow = Cells(Rows.Count, "A").End(xlUp).Row
        nColumn = Cells(nRow, Columns.Count).End(xlToLeft).Column
        Range(Cells(nRow, "A"), Cells(nRow, nColumn)).Select
    End Sub
    

提交回复
热议问题