Better way to find last used row

前端 未结 8 1146
情歌与酒
情歌与酒 2020-11-22 15:32

I am trying to make this way of finding the last row as I found the last column:

Sheets(\"Sheet2\").Cells(1,Sheets(\"Sheet2\").Columns.Count).End(xlToLeft).C         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 15:59

    How is this?

    dim rownum as integer
    dim colnum as integer
    dim lstrow as integer
    dim lstcol as integer
    dim r as range
    
    'finds the last row
    
    lastrow = ActiveSheet.UsedRange.Rows.Count
    
    'finds the last column
    
    lastcol = ActiveSheet.UsedRange.Columns.Count
    
    'sets the range
    
    set r = range(cells(rownum,colnum), cells(lstrow,lstcol))
    

提交回复
热议问题