You have not provided the code, so I will use a simple scenario.
2 workbooks "Book1" and "Book2", you want to copy Book1,Sheet1,A1 and paste it to Book2,Sheet1,A1.
With both workbooks open you would use the macro recorder and end up with a code like this, these codes will be in Book2
Sub Macro7()
Windows("Book1").Activate
Sheets("Sheet1").Select
Range("A1").Select
Selection.Copy
Windows("Book2").Activate
Sheets("Sheet1").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub
The following code will do the same thing without having to physically select Book1 to get the data.
Sub GetData1()
Dim wb1 As Workbook, wb2 As Workbook, _
ws1 As Worksheet, ws2 As Worksheet, c As Range, p As Range
Set wb1 = Workbooks("Book1")
Set wb2 = Workbooks("Book2")
Set ws1 = wb1.Worksheets("Sheet1")
Set ws2 = wb2.Worksheets("Sheet1")
Set c = ws1.Range("A1")
Set p = ws2.Range("A1")
c.Copy Destination:=p
End Sub
This may work as well.
Sub GetData2()
Workbooks("Book2").Worksheets("Sheet1").Range("A1") = Workbooks("Book1").Worksheets("Sheet1").Range("A1")
End Sub
Bookmarks