Better way to find last used row

前端 未结 8 1160
情歌与酒
情歌与酒 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:03

    This function should do the trick if you want to specify a particular sheet. I took the solution from user6432984 and modified it to not throw any errors. I am using Excel 2016 so it may not work for older versions:

    Function findLastRow(ByVal inputSheet As Worksheet) As Integer
        findLastRow = inputSheet.cellS(inputSheet.Rows.Count, 1).End(xlUp).Row
    End Function
    

    This is the code to run if you are already working in the sheet you want to find the last row of:

    Dim lastRow as Integer
    lastRow = cellS(Rows.Count, 1).End(xlUp).Row
    

提交回复
热议问题