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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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 :eeek:
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

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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