VBA: Cut, Copy, Paste from a Macro

Automate Excel

VBA: Cut, Copy, Paste from a Macro

It’s pretty easy to cut and paste from a macro. Here are a few examples. The code works identical for copy, just replace the word cut with copy!

This one cuts and pastes a single cell, a1 over to b1:

Sub OneCell()

    Range("A1").Select
    Selection.Cut
    Range("B1").Select
    ActiveSheet.Paste

    Application.CutCopyMode = False

End Sub

This one cuts and pastes an entire column, A over to B:

Sub OneColumn()

    Range("A:A").Select
    Selection.Cut
    Range("B:B").Select
    ActiveSheet.Paste

    Application.CutCopyMode = False

End Sub

This one cuts and pastes an entire row, 1 over to 2:

Sub OneRow()

    Range("1:1").Select
    Selection.Cut
    Range("2:2").Select
    ActiveSheet.Paste

    Application.CutCopyMode = False

End Sub

Related posts

4 Responses

  1. matthew Says:

    How do you paste it into specific cells in another worksheet?

  2. Diego Castro Says:

    From VBA help:
    Worksheets(”Sheet1″).Range(”A1:D4″).Copy _
    Destination:=Worksheets(”Sheet2″).Range(”E5″)

    Now I understand :)

  3. Marcelo Says:

    Hi,

    Could you please help-me in this situation…
    How to make this function work?
    I just need to call it in a cell like “=test_copy(B1)” to see it copied into B2
    I am new to vba, but I’m able to do some perl,c++

    regards,
    Marcelo

    Public Function test_copy(Var01 As Range)
    Var01.Select
    Selection.Copy
    Range(”B2″).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    End Function

  4. Matthew S Olmstead Says:

    Is there a way to cut a row/rows and insert it/them into a sorted order on a different page with other information? I can’t just insert them at the bottom and sort because the rows on the other page are merged and cannot be sorted. This is the last piece to my VBA puzzle. Thank you!

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.