添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

The basic thing we do in Excel is copy, cut, and paste the data from one cell to another. It requires no special introduction as well. However, learning VBA coding is important to understand the same concept in coding language. Copy paste in VBA is the routine task we do daily in Excel. To copy first, we need to decide which cell to copy.

Sub Copy_Example()
  Worksheets("Sheet1").Range("A1").Copy Destination:=Worksheets("Sheet2").Range("B3")
End Sub

Example #3 - Copy from One Workbook to another Workbook

We have seen how to copy from one worksheet to another worksheet in the same workbook. But, we can also do this from one workbook to another workbook.

Take a look at the below code.

Code:

SubCopy_Example()
  Workbooks("Book 1.xlsx").Worksheets("Sheet1").Range("A1").Copy
  Workbooks("Book 2.xlsx").Activate
  ActiveWorkbook.Worksheets("Sheet 2").Select
  ActiveSheet.Paste
End Sub

Firstly, it will copy the data from the worksheet "Sheet1" in the workbook "Book1.xlsx" from cell A1.

Workbooks("Book 1.xlsx").Worksheets("Sheet1").Range("A1").Copy”

Then it will activate the workbook “Book 2.xlsx”.

Workbooks("Book 2.xlsx").Activate

The active workbook will select the worksheet "Sheet 2."

ActiveWorkbook.Worksheets("Sheet 2").Select

Now in the active sheet, it will paste.

ActiveSheet.Paste

Alternative Way for using Copy-Paste in VBA

We have one more alternative way of having the data from one cell to another cell. Assume you have the word "Excel VBA" in cell A1 and you need the same to come in cell B3.

Sub Copy_Example2()
  Worksheets("Sheet1").UsedRange.Copy Destination:=Worksheets("Sheet2").Range("A1")
End Sub

It will copy the entire used range in the worksheet "Sheet1" and paste it into the worksheet "Sheet2."

Recommended Articles

This article has been a guide to VBA Copy Paste. Here, we discuss the top ways to copy and paste in VBA, examples, and a downloadable Excel template. Below are some useful Excel articles related to VBA: -