Find last row in range

前端 未结 11 2043
傲寒
傲寒 2020-12-02 00:41

I\'m having a little trouble with finding the last row.

What I am trying to do is find the last row in column "A", then use that to find the last row within

11条回答
  •  醉酒成梦
    2020-12-02 01:37

    Range().End will bring you to the end of a code block. If the starting cell is empty, it brings you the the first used cell or the last cell. It the cells is not empty it brings you to the last used cell. For this reason, you need to test whether or not the cell in column B is to determine whether to use LR_wbSelectNew as the last row.

    With wbshtSelect
        LR_wbSelect = .Cells(Rows.Count, "A").End(xlUp).Row - 22
    
        If .Cells(LR_wbSelect, "B") <> "" Then
            LR_wbSelectNew = LR_wbSelect
        Else
            LR_wbSelectNew = .Cells(LR_wbSelect, "B").End(xlUp).Row
        End If
    End With
    

    This code defines a Target range that extends from A1 to the last row in column a - 22 and extends 10 columns.

    Dim Target As Range
    With wbshtSelect
        Set Target = .Range("A1", .Cells(Rows.Count, "A").End(xlUp).Offset(-22)).Resize(, 10)
    End With
    

提交回复
热议问题