Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy data from one workbook to another with VBA
#1
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.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy data to another worksheet Qomplainerz 0 397 07-27-2023, 11:24 AM
Last Post: Qomplainerz
  Concatenate data in columns Qomplainerz 0 344 07-27-2023, 11:01 AM
Last Post: Qomplainerz
  Create a pivot table based on data in a worksheet with VBA Qomplainerz 0 413 07-27-2023, 09:48 AM
Last Post: Qomplainerz
  Filter data in a worksheet Qomplainerz 0 380 07-27-2023, 09:46 AM
Last Post: Qomplainerz
  Create a chart from data with VBA Qomplainerz 0 379 07-27-2023, 09:44 AM
Last Post: Qomplainerz
  Sort data in a range with VBA Qomplainerz 0 366 07-27-2023, 09:43 AM
Last Post: Qomplainerz
  Insert a new row and fill it with data in VBA Qomplainerz 0 343 07-27-2023, 09:11 AM
Last Post: Qomplainerz
  Add data validation to a cell with VBA Qomplainerz 0 353 07-27-2023, 09:10 AM
Last Post: Qomplainerz
  Copy and paste values with VBA Qomplainerz 0 346 07-27-2023, 09:08 AM
Last Post: Qomplainerz
  Running VBA code when a workbook is being opened Qomplainerz 0 253 07-27-2023, 07:03 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 4 Guest(s)