VBA: Cut, Copy, Paste from a Macro

August 18th, 2004 | Categories: VBA | Tags: , , , ,

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
  1. matthew
    October 17th, 2008 at 08:46
    Reply | Quote | #1

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

  2. Diego Castro
    March 30th, 2009 at 16:25
    Reply | Quote | #2

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

    Now I understand :)

    • Rashed
      February 3rd, 2010 at 03:50
      Reply | Quote | #3

      Simply Excellent Code

  3. Marcelo
    June 1st, 2009 at 11:19
    Reply | Quote | #4

    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. June 10th, 2009 at 21:52
    Reply | Quote | #5

    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!

  5. Zach
    July 15th, 2009 at 19:45
    Reply | Quote | #6

    how do you copy a column from one workbook and paste it in another?

  6. Chris
    August 7th, 2009 at 13:58
    Reply | Quote | #7

    How do you copy Range A7:C11 from the first sheet to all sheets of the workbook (also to A7:C11 on every sheet)? Thanks!

  7. Jeff
    August 25th, 2009 at 00:16
    Reply | Quote | #8

    Hi, when complex vba routines run in the background of excel, it becomes impossible to use copy and pate in other applications. Any workaround for this? Cheers, Jeff

  8. Sandheep
    August 27th, 2009 at 14:56
    Reply | Quote | #9

    How do I copy the cell no. and paste it another cell. Suppose I want the cell no. of the word “Significant” in the worksheet. Assuming it is in B4. How do I paste it in C1 using macro? The macro should be able to find the cell no.

  9. Rahul
    November 23rd, 2009 at 15:47

    Hi

    I have data in 50 worksheets in a workbook (in same format). Can I copy all data and paste it in a New Worksheet, so that a Master File can be created.

  10. Aaron
    January 8th, 2010 at 20:29

    I have four rows of data that need to be pastes into another worksheet in 1 column? How do I do this?

    I have been trying to set cells equal by value, but for some reason, they can’t transpose automatically.

    I have also tried the if then statements so that if the data is greater than zero, then the cell automatically paste into the other sheet, but that wont work either? Any ideas as to how to get multiple rows paste into one column across sheets?

  11. Logs
    January 19th, 2010 at 23:25

    Hi,
    I need to do a find of a certain word in my worksheet, then cur the entire row it is in and insert that into the first row. Which is easy enough.. but the row the particular word is in changes each time… How can i make it cut a different row each time the Macro is run?

  12. Norman
    March 8th, 2010 at 17:14

    Is there a way, using an input form, to tell the macro where to start pasting information? For example:

    The typical command is: Range(“B2″).Select
    I want to be able to tell the macro a different cell to copy to starting somewhere other than “B2″. Maybe B3 or B4.