Open another workbook and copy from another workbook until the last row to the active workbook

Cakz Primz

Board Regular
Joined
Dec 4, 2016
Messages
102
Office Version
  1. 365
Platform
  1. Windows
Dear All,

I need your help. I want to copy the entire row from "AXREP" sheet in "AXREP" workbook into my active sheet, "AXREP" in "MY AXREP" workbook.
So far, the code below is working, but the problem I don't know the code to copy until the last row from another workbook. I want selected range to copied is dynamic.
Right now, the selected range is not dynamic, see the bold line.

VBA Code:
    Windows("AXREP.xlsb").Activate
    [B][I]Workbooks("AXREP.xlsb").Worksheets("AXREP").Range("A2:CC150000").Copy[/I][/B]
    Workbooks("MY AXREP.xlsb").Worksheets("AXREP").Range("A3").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False


VBA Code:
Sub OpenCopyPaste()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim ws As Worksheet
    Set ws = ActiveSheet
    Dim lRow As Long
    lRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    With ws
      .Range("A3:CC" & lRow).ClearContents
    End With
    
    Call GetLatestAXREP 'Open latest file of AXREP.xlsb
    
    Windows("AXREP.xlsb").Activate
    [B][I]Workbooks("AXREP.xlsb").Worksheets("AXREP").Range("A2:CC150000").Copy[/I][/B]
    Workbooks("MY AXREP.xlsb").Worksheets("AXREP").Range("A3").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub

I hope that someone would like to help me.
Thanks so much in advance.

Prima-Indonesia
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
These two changed should do but I'm assuming that coloumn A of Workbooks("AXREP.xlsb").Worksheets("AXREP") contains data in the last used row.
VBA Code:
'...
Windows("AXREP.xlsb").Activate
lRow = Worksheets("AXREP").Cells(Rows.Count, 1).End(xlUp).Row     '<- added
Workbooks("AXREP.xlsb").Worksheets("AXREP").Range("A2:CC" & lRow).Copy '<- changed
Workbooks("MY AXREP.xlsb").Worksheets("AXREP").Range("A3").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
'...
 
Upvote 0
Solution
Dear rollis13,

Thanks so much for your help and assistance. You save my day.
Really appreciate it.

Problem solved !!!

Thank you rollis13
Thank you MrExcel


These two changed should do but I'm assuming that coloumn A of Workbooks("AXREP.xlsb").Worksheets("AXREP") contains data in the last used row.
VBA Code:
'...
Windows("AXREP.xlsb").Activate
lRow = Worksheets("AXREP").Cells(Rows.Count, 1).End(xlUp).Row     '<- added
Workbooks("AXREP.xlsb").Worksheets("AXREP").Range("A2:CC" & lRow).Copy '<- changed
Workbooks("MY AXREP.xlsb").Worksheets("AXREP").Range("A3").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
'...
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,223,637
Messages
6,173,488
Members
452,515
Latest member
archcalx

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