Copy Data between Workbooks

DenialDan

New Member
Joined
May 31, 2017
Messages
15
Hello,

I've been trying to get this to work:
I have one workbook which contains new data every week. When I run the macro I want it to open that workbook and copy data from a set range into the workbook that contains the executed macro.
The set range to copy is from one cell (top left) to the end of the worksheet 6 (bottom right). I was able to save the bottom left cell to copy into a variable but I can't figure out a way to use it in my copy range.

Code:
Private Sub ADRMoP_Click()


Dim ADRM As Workbook
Set ADRM = Workbooks.Open("<Workbook Address on Drive>")


Dim EndCell As Range
' Bottom left cell as variable
Set EndCell = ADRM.Sheets(6).Range("A1").SpecialCells(xlCellTypeLastCell).Offset(-2, 0)


Dim CopyRange As Range
' Here's my problem. I can't put the variable into my range method
Set CopyRange = ADRM.Sheets(6).Range("B3:EndCell.Address()")
CopyRange.Copy
Sheets("Line Items_oP").Range("B4").Paste


ADRM.Close


End Sub

Kind regards,
Daniel.
 
I've resolved the issue. The code I used at the end was the following:
Code:
Private Sub ADRMoP_Click()

Dim FC As Workbook
Set FC = ThisWorkbook
Dim ADRM As Workbook
Set ADRM = Workbooks.Open(" ")


Dim EndCell As Range
Set EndCell = ADRM.Sheets(6).Range("A1").SpecialCells(xlCellTypeLastCell).Offset(-2, 0)


Dim CopyRange As Range
Set CopyRange = ADRM.Sheets(6).Range("B3:" & EndCell.Address)
CopyRange.Copy
FC.Sheets(5).Range("B4").PasteSpecial xlPasteAll

ADRM.Close

End Sub

Weirdly enough the problem was that I wanted to paste it in Sheet 6 but it needed to be pasted into Sheet 5. In VBE it said the needed Sheet was 6 but whatever. :confused:

Thanks for the help. :)
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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