Copy specific cells from one workbook to another.

Copper Contributor

Good morning. 

I am trying to copy specific cells from one workbook to another. 

Per sample input attached, I'm trying to copy ONLY cells  B3 to F10 into the same cells (B3 to F10) in another workbook. 

 

I was using this code in the new workbook, but it's erroring out:

filter = "Excel files (*xlsx), *.xlsx"

Caption = "Please Select Sample Input data"

Ret = False Then Exit Sub
Set wb = Workbooks.Open(Ret)

wb.Sheets(1).UsedRange.Copy targetWorkbook.Sheets ("Sample").Range("B3:F10").Select

wb.CLose False

MsgBox ("Sample data has been imported")

 

Error: Run-time error '1004':

Unable to get the Select property of the Range class

------------------------------

If I remove .Select at the end of line 5:

wb.Sheets(1).UsedRange.Copy targetWorkbook.Sheets ("Sample").Range("B3:F10")

It copies the entire sheet instead of the specific cells. 

 

------------------------------

I also tried removing the UsedRange with Select option:

wb.Sheets(1).Copy targetWorkbook.Sheets ("Sample").Range("B3:F10").Select

Error: Run-time error '1004':

Unable to get the Select property of the Range class

 

------------------------------

And finally removed .Select so it reads:

wb.Sheets(1).Copy targetWorkbook.Sheets ("Sample").Range("B3:F10")

I instead get error 

Run-Time error '1004'

Copy method of Worksheet class failed.

 

------------------------------

I'm going down a rabbit hole, any help is appreciated. 

1 Reply

@JoseP1504 

wb.Sheets(1).Range("B3:F10").Copy targetWorkbook.Sheets ("Sample").Range("B3:F10")