Copy and Paste a set range in the next empty row

前端 未结 4 1134
时光取名叫无心
时光取名叫无心 2020-12-15 13:19

This should be simple but I am having a tough time.. I want to copy the cells A3 through E3, and paste them into the next empty row on a different worksheet. I have used thi

4条回答
  •  抹茶落季
    2020-12-15 14:21

    The reason the code isn't working is because lastrow is measured from whatever sheet is currently active, and "A:A500" (or other number) is not a valid range reference.

    Private Sub CommandButton1_Click()
        Dim lastrow As Long
    
        lastrow = Sheets("Summary Info").Range("A65536").End(xlUp).Row    ' or + 1
        Range("A3:E3").Copy Destination:=Sheets("Summary Info").Range("A" & lastrow)
    End Sub
    

提交回复
热议问题