Better way to find last used row

前端 未结 8 1089
情歌与酒
情歌与酒 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条回答
  •  失恋的感觉
    2020-11-22 16:07

    I preferred search last blank cell:

    Il you want last empty cell of column you can do that

    Dim sh as Worksheet, r as range
    set sh = ActiveWorksheet 'if you want an other it's possible
    
    'find a value 
    'Columns("A:D") 'to check on multiple columns 
    Set r = sh.Columns("A").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
    'no value return first row
    If r Is Nothing Then Set r = sh.Cells(1, "A") Else Set r = sh1.Cells(r.Row + 1, "A")
    

    If this is to insert new row, find on multiple columns is a good choice because first column can contains less rows than next columns

提交回复
热议问题