Search code examples
excelvbarangefinance

How to copy Range and past to last row


I have a user input transaction information (Name, Amount, Date) in cells E33:G33.

User clicks button and the transaction is recorded in the last row +1 used in a Transaction history list starting on E46:G46.

So far my code doesnt work.

i want simply: -copy range (E33:G33) -find last row used in column E -go one row lower -past the copied range

Cant find a working answer, please help! Thanks.


Solution

  • use this:

    Sub test()
    Dim e&: e = Cells(Rows.Count, "E").End(xlUp).Row + 1
    Range("E" & e & ":G" & e).Value = [E33:G33].Value 'past only values
    End Sub
    

    or

    Sub test2()
    Dim e&: e = Cells(Rows.Count, "E").End(xlUp).Row + 1
    [E33:G33].Copy Range("E" & e & ":G" & e) 'past with cells format
    End Sub
    

    or

    Sub test3()
    Dim e&: e = Cells(Rows.Count, "E").End(xlUp).Row + 1
    [E33:G33].Copy
    Range("E" & e & ":G" & e).PasteSpecial xlPasteAll 'past with cells format
    End Sub
    

    or

    Sub test4()
    Dim e&: e = Cells(Rows.Count, "E").End(xlUp).Row + 1
    [E33:G33].Copy
    Range("E" & e & ":G" & e).PasteSpecial xlPasteValues 'past only values
    End Sub
    

    also:

    [E33:G33] can be replaced by:

    Range("E33:G33")

    or

    Cells(Cells(33,"E"),Cells(33,"G"))

    or

    Cells(Cells(33,5),Cells(33,7))