Copy one worksheet to another from different workbook

Jeffreyxx01

Board Regular
Joined
Oct 23, 2017
Messages
156
Hi guys,

Can someone help me to write a code that copy one worksheet from one workbook to another worksheet in another workbook.
I need to automate a few tasks at work and I cannot make complex macro.

Thanks for your support.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi Fluff, why does the code paste as values does not work?

Code:
Sub OpenFile()   
   Dim Fname As String
   Dim Wbk As Workbook
   Dim Sht As Worksheet
   
   Set Sht = ActiveWorkbook.Sheets("PW")
   ChDrive "W:"
   ChDir "W:\Insights Team\ALL ACADEMIC\Reporting\Weekly RAM\Pathways"
   Fname = Application.GetOpenFilename(FileFilter:="xls Files (*.xls*), *.xls*", Title:="Select a file", MultiSelect:=False)
   If Fname = "False" Then
      MsgBox "no file selected"
      Exit Sub
   Else
      Set Wbk = Workbooks.Open(Fname)
      With Wbk.Sheets("Summary for BP")
         Sht.Range("s6:W27").ClearContents
         .Range("i7:M28").Copy Sht.Range("s6")
         .PasteSpecial _
         Paste:=xlValues
         
Application.CutCopyMode = False
      End With
 Application.DisplayAlerts = False
      Wbk.Close , False
   End If


End Sub
 
Upvote 0
Look at how you had it in post#48
 
Upvote 0
Hi Fluff,

Is it possible to have a code that looks the same as post #48 but like one file that feeds 20 tabs in another?

Code:
Sub OpenFile()   Dim Fname As String
   Dim Wbk As Workbook
   Dim Sht As Worksheet
   Dim Usdrws As Long
   Dim Ary As Variant
   Dim Info As String
   Dim Cnt As Long
   
   Info = "January'18 Summary|M41:Q54|L5:P18|Historical Data|X29:AH36|H41:R48|Historical Data|X44:AE51|H23:O30"
   Ary = Split(Info, "|")


   Set Sht = ActiveWorkbook.Sheets("NAME")
   ChDrive "W:"
   ChDir "W:\Insights Team\ALL GROUP\KPI"
   Fname = Application.GetOpenFilename(FileFilter:="xls Files (*.xls*), *.xls*", Title:="Select a file", MultiSelect:=False)
   If Fname = "False" Then
      MsgBox "no file selected"
      Exit Sub
   Else
      Set Wbk = Workbooks.Open(Fname)
      For Cnt = LBound(Ary) To UBound(Ary) Step 3
         With Sht.Range(Ary(Cnt + 1))
            .ClearContents
            .Value = Worksheets(Ary(Cnt)).Range(Ary(Cnt + 2)).Value
         End With
      Next Cnt
      Application.DisplayAlerts = False
      Wbk.Close , False
      Application.DisplayAlerts = True
   End If
   
End Sub
 
Upvote 0
I forgot to mention,

For example, I have one sheet called OTC with range a1:z100 to be paste as values to OTC range a1:z100 in another workbook on the tab called OTC
Then I have another called XYZ with range a1:z100 to go to XYZ same range,
But everything that goes to the second workbook come from the same workbook.

I just need that because I have linked the second workbook to some work.

If you see what I mean, that would be great
 
Upvote 0
Not sure if I've understood correctly, but if all the ranges are the same try
Code:
Sub OpenFileCopy()
   Dim Fname As String
   Dim SrcWbk As Workbook
   Dim DestWbk As Workbook
   Dim Usdrws As Long
   Dim Ary As Variant
   Dim Cnt As Long
   
   Ary = Array("[COLOR=#ff0000]MA[/COLOR]", "[COLOR=#ff0000]Pick[/COLOR]", "[COLOR=#ff0000]Test[/COLOR]", "[COLOR=#ff0000]Sheet1[/COLOR]")

   Set DestWbk = ThisWorkbook
   ChDrive "W:"
   ChDir "W:\Insights Team\ALL GROUP\KPI"
   Fname = Application.GetOpenFilename(FileFilter:="xls Files (*.xls*), *.xls*", title:="Select a file", MultiSelect:=False)
   If Fname = "False" Then
      MsgBox "no file selected"
      Exit Sub
   Else
      Set SrcWbk = Workbooks.Open(Fname)
      For Cnt = LBound(Ary) To UBound(Ary)
         DestWbk.Sheets(Ary(Cnt)).Range("A1:Z100").Value = _
            SrcWbk.Sheets(Ary(Cnt)).Range("A1:Z100").Value
      Next Cnt
      Application.DisplayAlerts = False
      Wbk.Close , False
      Application.DisplayAlerts = True
   End If
   
End Sub
Change the values in red to match your sheet names
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,588
Members
449,520
Latest member
TBFrieds

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