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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Ok, how about
Code:
    UsdRws = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 
Upvote 0
Hi again Fluff,

there is a problem in the code
When I use the code just by clicking F5, there is no problem but when I make a button, the click copy the title for the second line from AE2:BA2

Can you tell me how to fix it?

Code:
Sub OpenFile()   
   Dim Fname As String
   Dim Wbk As Workbook
   Dim Sht As Worksheet
   Dim Usdrws As Long
   
   Set Sht = ActiveWorkbook.Sheets("Pipeline")
   ChDrive "W:"
   ChDir "W:\Insights Team\ALL ACADEMIC\Reporting\Weekly RAM\OTC\Magdalena Spreadsheet"
   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("Registration Enquiry")
         Sht.Range("A2:ad1000").ClearContents
         .Range("A2:ad1000").Copy Sht.Range("A2")
      End With
      Wbk.Close , False
            Usdrws = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            Sht.Range("AE2:BA" & Usdrws).FillDown
   End If


End Sub
 
Upvote 0
Oops should be
Code:
Usdrws = [COLOR=#ff0000]Sht.[/COLOR]Cells.
 
Upvote 0
Hello Fluff,

I need the code to paste the data from where it copies to the new sheet in values. I have written something but it does not copy as values.
Please can you help?

Code:
Sub OpenFile()
   
   Dim Fname As String
   Dim Wbk As Workbook
   Dim Sht As Worksheet
   Dim Usdrws As Long
   
   Set Sht = ActiveWorkbook.Sheets("OTC")
   ChDrive "W:"
   ChDir "W:\Insights Team\ALL ACADEMIC\Reporting\Weekly RAM\OTC\Weekly RAM"
   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("January'18 Summary")
         Sht.Range("m41:q54").ClearContents
         .Range("l5:p18").Copy Sht.Range("m41")
         .PasteSpecial xlPasteValues
         Application.CutCopyMode = False
      End With
        Application.DisplayAlerts = False
        Wbk.Close , False
        
   End If


End Sub
 
Upvote 0
Try
Code:
   .Range("l5:p18").Copy
   Sht.Range("m41").PasteSpecial xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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