Copy a sheet from a closed workbook and paste on an existing sheet of this workbook

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I need to copy the sheet ("Alpha") from the closed workbook ("Beta") and paste it in thisworkbook sheet ("Alpha").

Code:
Sub copy_alpha()
     Application.ScreenUpdating = False
     Set wb1 = thisworkbook
     Set file2 = Workbooks.Open("S:\xxxx\yyyyyy\Beta.xls")
     file2.Sheets("Alpha").Copy wb1.Sheets("Alpha")
     file2.Close
     Application.ScreenUpdating = True
End Sub

Unfortunately, with this code a new sheet is generated in thisworkbook ("Alpha(2)"), instead of pasting in the pre existing sheet Alpha.

Could anyone help me?
 
Last edited by a moderator:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Code:
Sub copy_alpha()
     Dim wb1 As Workbook, file2 As Workbook
     Application.ScreenUpdating = False
     Set wb1 = ThisWorkbook
     Set file2 = Workbooks.Open("[I][COLOR=#000080]C:\folder\subfolder\filename.xlsx[/COLOR][/I]")
     file2.Sheets("Alpha").Copy After:=wb1.Sheets(wb1.Sheets.Count)
     file2.Close False
     Application.ScreenUpdating = True
End Sub
 
Upvote 0
Maybe
Code:
Sub copy_alpha()
     Application.ScreenUpdating = False
     Set WB1 = ThisWorkbook
     Set File2 = Workbooks.Open("S:\xxxx\yyyyyy\Beta.xls")
     File2.Sheets("Alpha").UsedRange.Copy WB1.Sheets("Alpha").Range("A" & Rows.Count).End(xlUp).Offset(1)
     File2.Close
     Application.ScreenUpdating = True
End Sub
 
Upvote 0
@Nelson78 - it would be best if you ignore my suggestion :eek:
user-offline.png
 
Last edited:
Upvote 0
It's all clear, except the text highlighted in red.

Maybe
Code:
     File2.Sheets("Alpha").UsedRange.Copy WB1.Sheets("Alpha").Range("A" & Rows.Count).End(xlUp).[COLOR="#FF0000"]Offset(1)[/COLOR]
 
Upvote 0
The part in red simply moves down 1 row.
 
Upvote 0
I was wondering why you inserted that instruction.
Maybe in order to preserve the header?
Yes, I wasn't sure if you already had data in that sheet.
 
Upvote 0

Forum statistics

Threads
1,214,790
Messages
6,121,607
Members
449,037
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top