How to select the lastrow

前端 未结 2 1357
后悔当初
后悔当初 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:31

    How about this:

    Sub GetLastRow()
        Dim rng As Range, lastRow As Long, col As Long
    
        lastRow = Range("A1").End(xlDown).Row //Get last row in column A
        col = Range("XFD" & lastRow).End(xlToLeft).Column //Get last used column in last row
    
        Set rng = Range(Cells(lastRow, 1), Cells(lastRow, col))
    End Sub
    

提交回复
热议问题