简体   繁体   中英

Copying cell range from a workbook sheet to another workbook sheet

I have 3 workbooks, namely: A, B and C.

I'm coding a VBA macro inside A in order to copy cell range content of a particular sheet from B to C.

Dim wb_TC_PBS As Excel.Workbook
Dim wb_SPO_PBS As Excel.Workbook

Set wb_TC_PBS = Workbooks.Open("C:\temp\migration\B.xlsm")
Application.CutCopyMode = False
FinalRow = Sheets("TC_PBS").Cells(Rows.Count, 1).End(xlUp).Row
Range("A5:EO" & FinalRow).Copy

I would like to understand if my approach is correct and how to continue pasting content on workbook C

Here this might help

Dim a As Workbook,b As Workbook, c As Workbook, FinalRow As Long

Set a = ThisWorkbook
Set b = Workbooks.Open("C:\temp\migration\B.xlsm")
Set c = Workbooks.Open("C:\temp\migration\C.xlsm")

b.Activate
FinalRow = b.Sheets("TC_PBS").Cells(Rows.Count, 1).End(xlUp).Row
b.Sheets("TC_PBS").Range("A5:EO" & FinalRow).Copy
c.Activate
c.Worksheets(1).Range("A1").Select
c.Sheet1.Paste
Application.CutCopyMode = False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM