VBA to Cut Range in Excel – Examples
Here is the simple example to cut and copy a paste. In this example , we cut the data at Range “A2:D10” and copy to the Clipboard and then Pasting in the Range “E2”.
Range("A2:D10").Cut 'This will cut the source range and copy the Range "A2:D10" data into Clipboard
'Now you can select any range and paste there
VBA to Cut and paste the Range to Destination in Excel – Example
Here is the another example to cut and copy a range to specific range and directly paste into another location of the worksheet. In this example , we cut the range “A2:D10” and pasting at Range “E2”.
'Or you can write as Range("A2:D10").Cut Destination:=Range("E2")
VBA to Cut Range in Excel – Execution Instructions
You can follow the below steps to execute the macro to cut and paste a range using VBA.
- Open an Excel Workbook from your start menu or type Excel in your run command
- Enter some data in any cells in range “A2:D10″ to test this macro.
- 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
- Insert a Module from Insert Menu of VBA
- Copy the above code (to cut a range using VBA) and Paste in the code window(VBA Editor)
- Save the file as Macro Enabled Workbook (i.e; .xlsm file format)
- 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 cleared and pasted in the specific range. This will cut the range including its formats and other elements in that particular range.