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.
 
Hello Fluff,
Can you please help me on this modification of the macro:

Code:
Sub OpenFile()   
   Dim Fname As String
   Dim Wbk As Workbook
   Dim Sht As Worksheet
   Dim LastRow As Long


   
   Set Sht = ActiveWorkbook.Sheets("Pipeline")
   ChDrive "W:"
   ChDir "W:\Insights Team\ALL ACADEMIC\Reporting\Weekly RAM\Pathways\Weekly Tracker"
   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("P-pipeline")
        LastRow = Range("A:S").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
         Sht.Range("A4:LastRow").ClearContents
         .Range("A4:LastRow").Copy Sht.Range("A4")
      End With
        Application.DisplayAlerts = False
   Wbk.Close , False
        Application.DisplayAlerts = True
   End If


End Sub

I want the macro to copy until the last row and to paste the same in the other workbook, but I have a bug on the lastrow formula.
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try
Code:
Sub OpenFile()
   Dim Fname As String
   Dim Wbk As Workbook
   Dim Sht As Worksheet
   Dim LastRow As Long


   
   Set Sht = ActiveWorkbook.Sheets("Pipeline")
   ChDrive "W:"
   ChDir "W:\Insights Team\ALL ACADEMIC\Reporting\Weekly RAM\Pathways\Weekly Tracker"
   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("P-pipeline")
        LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
         Sht.Range("A4:S" & LastRow).ClearContents
         .Range("A4:S" & LastRow).Copy Sht.Range("A4")
      End With
        Application.DisplayAlerts = False
   Wbk.Close False
        Application.DisplayAlerts = True
   End If


End Sub
 
Upvote 0
Hi Fluff,

I have a question or request to ask you,

Is there any ways to create a macro that copy and paste 4 different sheets into a single one and slide down the formula automatically (like the one you made), but the thing is I want the macro to copy and paste at the following row by finding the last row in each sheet and pasting into one workbook.
I don't know if it makes sense?

Thanks.
 
Upvote 0
If I've understood you correctly & using the previous code as an example
Code:
   With Wbk.Sheets("P-pipeline")
      lastrow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
      .Range("A4:S" & lastrow).Copy Sht.Range("A" & Rows.Count).End(xlUp).Offset(1)
   End With
This will copy the data from sheet & paste to 1 row below the last used cell in col A
 
Upvote 0
Well it is a totally new report with the same idea as the one,

I want to copy 4 different worksheets coming from different workbooks each into 1 and slide down the formula on the right-hand side,
So like, the data copied come from A2:S, and all have to find the last row and copy into one and paste at the following.
 
Upvote 0
Sub OpenFile()
Dim Fname As String
Dim Wbk As Workbook
Dim Sht As Worksheet
Dim LastRow As Long



Set Sht = ActiveWorkbook.Sheets("Pipeline")
ChDrive "W:"
ChDir "W:\has to be changed"
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("has to be changed")
LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Sht.Range("A4:S" & LastRow)
.Range("A4:S" & LastRow).Copy Sht.Range("A4")
End With
Application.DisplayAlerts = False
Wbk.Close False
Application.DisplayAlerts = True
End If


End Sub
 
Upvote 0
I want to adapt the code at the top to select 4 sheets and to paste under each.
using the range to copy at a2:s for each report to be copied and paste under each other starting from A4
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,222
Members
453,024
Latest member
Wingit77

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