Copy data from one workbook to another with VBA - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48) +--- Thread: Copy data from one workbook to another with VBA (/showthread.php?tid=5243) |
Copy data from one workbook to another with VBA - Qomplainerz - 07-27-2023 Example: Sub CopyData() Dim sourceSheet As Worksheet Dim destinationSheet As Worksheet 'Set the source and destination sheets Set sourceSheet = ThisWorkbook.Sheets("Sheet1") Set destinationSheet = ThisWorkbook.Sheets("Sheet2") 'Copy data from source to destination sourceSheet.Range("A1:C10").Copy destinationSheet.Range("A1") End Sub Explanation: This code defines a subroutine named CopyData. It declares two variables sourceSheet and destinationSheet, representing the worksheets from which you want to copy data and where you want to paste it. The Set statement is used to specify the source and destination sheets (Sheet1 and Sheet2) within the same workbook. The Copy method is then used to copy the data from cell range A1:C10 on sourceSheet to cell range A1 on destinationSheet. The Copy method is used to copy a range of cells from one worksheet to another. The method is invoked on the source range (sourceSheet.Range("A1:C10")) and specifies the destination range (destinationSheet.Range("A1")) as the place where the data will be pasted. |