VBA Copy Range in Excel Explained with Examples

We can use VBA to Copy a Range to another location or range. Range.Copy method will copy and it will save the copied data in Clipboard then you can select any range and paste. You can also specify the destination range while copying a range.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


VBA Copy Method Excel Range Object

VBA to Copy Range in Excel – Syntax

Here is the syntax to copy a range using VBA. Here, Destination is the range which you want to be copied. This is optional, you are not providing the destination range, this will copy to the Clipboard.

Range(“YourRange”).Copy(

[Destination])

VBA to Copy Range in Excel – Examples

Here is the simple example to copy a range. In this example, we are copying Range “A2:D10” to the Clipboard and then Pasting in the Range “E2”.

Sub Copy_Range_To_Clipboard()
Range("A2:D10").Copy 'This will copy the Range "A2:D10" data into Clipboard
'Now you can select any range and paste there
Range("E2").Select
ActiveSheet.Paste
End Sub

VBA to Copy Range to Destination in Excel – Example

Here is the another example to copy a range to specific range. In this example, we are copying Range “A2:D10” and pasting at Range “E2”.

Sub Copy_Range_To_Destination_Range()
Range("A2:D10").Copy Range("E2")
'Or you can write as Range("A2:D10").Copy Destination:=Range("E2")
End Sub

VBA to Copy Range in Excel – Execution Instructions

You can follow the below steps to execute the macro for copying a range using VBA.

  1. Open an Excel Workbook from your start menu or type Excel in your run command
  2. Enter some data in any cells in range “A2:D10″ to test this macro.
  3. Press Alt+F11 to Open VBA Editor or you can go to Developer Tab from Excel Ribbon and click on the Visual Basic Command to launch the VBA Editor
  4. Insert a Module from Insert Menu of VBA
  5. Copy the above code (for copying a range using VBA) and Paste in the code window(VBA Editor)
  6. Save the file as Macro Enabled Workbook (i.e; .xlsm file format)
  7. Press ‘F5′ to run it or Keep Pressing ‘F8′ to debug the code line by line.

Now you can observe that the Range A2:D10 is copied to specific range. This will copy the range including its formats and other elements in that particular range. To copy the specific elements, see the examples on PaseSpecial.

LIMITED TIME OFFER

3 Comments

  1. Gerald Alonzo November 26, 2015 at 11:22 PM - Reply

    How do I copy a local 2 dimensional array of data to spreadsheet?
    VBA code example
    Dim MyData(0 To 50, 0 To 200)
    ‘ code to fill MyData() with values
    Range(MyData).Copy Range(“ULCorner”) ‘ULCorner” is a named cell in worksheet

    • PNRao November 27, 2015 at 4:54 PM - Reply

      Hi Gerald,

      Here is the code for the above question.

      Sub Move_2Dimentional_Data_To_Worksheet()
      Dim MyData(0 To 1, 0 To 2)
      MyData(0, 0) = 1
      MyData(0, 1) = 2
      MyData(0, 2) = 3
      MyData(1, 0) = 4
      MyData(1, 1) = 5
      MyData(1, 2) = 6
      For i = 0 To UBound(MyData, 1)
      For j = 0 To UBound(MyData, 2)
      Sheet3.Cells(i + 1, j + 1) = MyData(i, j)
      Next
      Next
      End Sub
      

      Regards-Valli

  2. Donovan March 15, 2016 at 6:18 PM - Reply

    How do I copy the contents of a range over without changing the formatting of the range that I am pasting to?

    Example:
    Starting a new reporting month. I want to retain info for the last 12 months, hence I want to remove the oldest month and all the data in its column and add a new month at the end of my range. However, when I “move” (by copy and pasting using a VBA command), I want to paste the values only, not the formatting.

    How do I do this?

Leave A Comment


Related pages


useful excel add inshow to unprotect a workbookbasic excel for beginnersdelete sheet vbaexcel worksheet name from cell valueexcel vba best practicesexcel test for empty cellexcel macro print to pdfhow to consolidate excel filesvba worksheet deletems access vba msgboxcase when vbachange rows to columns in excelexamples of spread sheetsmessage box vbsvba excel save workbookvba color numbershow to remove password from protected excel sheet 2007list of shortcut keys in excelinsert row excel 2007vba excel copy worksheetvba trim stringexcel macro tutorialsword add developer tab to ribbonexcel presentation templatesexcel timelines templatevba active rangehow to unhide excel columnsmultiple conditions excelexcel developer ribbonexcel vba fileactive worksheet vbadefine activexhow to unprotect excelvba find value in rangeexcel task scheduler templateexcel forms vbasql interview questions and answers pdfvbscript filesystemobject methodsms project templates 2010excel how to sort alphabeticallyvba excel copymacro in excel 2010 with exampledefine activexunprotecting an excel spreadsheetexcel macro creationhow to autofit columns in excelcount number of rows in excel vbahow to sort alphabetically in excelexample of vlookup formula in excelvba command button codecheck duplicates excelexcel sheet formulas with examplevba loop examplesadvantages microsoft excelhow to make radio buttons in excellearn macro excelsql queries interview questions and answers pdf free downloadsample excel formulas and functionsvba stockstacked pyramid chart excelsql interview questions and answers pdf for freshersvba case statementremove duplicates excel 2013excel vba refreshxlupswot analysis template for powerpointinsert row excel 2007sub vba excelhow to insert a row in excelremove empty rows in excelconsolidate function excelexcel findbvba code to read excel fileexcel 2010 vlookup multiple criteriaisna functionexcel shortcutsql interview questions for freshers pdf