Find the last cell address using vba excel

前端 未结 4 528
我在风中等你
我在风中等你 2020-12-11 00:07

I have searched this site and it seems like all the answers just point to finding the row number of the cell.

I am trying to set a range so that it will go from

4条回答
  •  甜味超标
    2020-12-11 00:54

    Try using something like this:

    Activesheet.Cells(Activesheet.Rows.Count, "A").End(xlUp).Row
    

    You can replace Activesheet with references to a sheet's index # like Sheets(1) or the sheet name like Sheets("Sheet1")

    By using the Rows.Count it will check to see what the max rows are and be compatible across all versions of Excel.

    In the end you can use this within your range reference like this:

    Msgbox Sheets(1).Range("A" & Sheets(1).Cells(Sheets(1).Rows.Count, "A").End(xlUp).row).value
    

    But I'd probably rewrite that as

    With Sheets(1)
        Msgbox .Range("A" & .Cells(.Rows.Count, "A").End(xlUp).row).value
    End With
    

提交回复
热议问题