Copying data from one WB to another?

afc171

Board Regular
Joined
Jan 14, 2017
Messages
143
Office Version
  1. 2013
Platform
  1. Windows
Hi guys, I have this code running but when it comes to pasting in B2 I keep getting an error: 348

I just need to copy the cells in columns from A2 to C2 then down to the last empty row and paste into V2 file in B2 :confused:

Code:
Sub Copy()
Dim x As Workbook
Dim y As Workbook

Set x = Workbooks.Open("O:\Public\Ads\1\V2.xlsm")

'Copies Product info:
     lastCol = ActiveSheet.Range("A2").End(xlToRight).Column
     lastRow = ActiveSheet.Cells(65536, lastCol).End(xlUp).Row
     ActiveSheet.Range("A2", ActiveSheet.Cells(lastRow, lastCol)).Copy

'Now, paste to y worksheet:
     Workbooks("V2.xlsm").Worksheets("Input").Range ("B2")
     
End Sub

Must be a way, someone else made this but cannot work out the copy part as it wants to copy past B2?

Thanks
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about
Code:
Sub Copy()
Dim x As Workbook

Set x = Workbooks.Open("O:\Public\Ads\1\V2.xlsm")

     lastcol = Cells(2, Columns.Count).End(xlToLeft).Column
     LastRow = Cells(Rows.Count, lastcol).End(xlUp).Row
     Range("A2", Cells(LastRow, lastcol)).Copy x.Sheets("Input").Range("B2")
End Sub
 
Upvote 0
Thanks Fluff,
It goes to the other sheet but nothing is being pasted?
 
Upvote 0
Do you just want columns A:C & will col A always have data for every row?
 
Upvote 0
Yes Fluff, Column A will have data but can be any amount of rows
 
Upvote 0
Ok, how about
Code:
Sub Copy()
Dim x As Workbook

Set x = Workbooks.Open("O:\Public\Ads\1\V2.xlsm")

Range("A2", Range("A" & Rows.Count).End(xlUp).Offset(, 2)).Copy x.Sheets("Input").Range("B2")
End Sub
 
Upvote 0
Ok, how about
Code:
Sub Copy()
Dim x As Workbook

Set x = Workbooks.Open("O:\Public\Ads\1\V2.xlsm")

Range("A2", Range("A" & Rows.Count).End(xlUp).Offset(, 2)).Copy x.Sheets("Input").Range("B2")
End Sub

Not copying anything over, I tried on a blank workbook just incase, but it does not copy the Product data for some reason.
 
Upvote 0
How about
Code:
Sub Copy()
Dim x As Workbook
Dim Rng As Range
Set Rng = Range("A2", Range("A" & Rows.Count).End(xlUp).Offset(, 2))
Set x = Workbooks.Open("O:\Public\Ads\1\V2.xlsm")

Rng.Copy x.Sheets("Input").Range("B2")
End Sub
 
Upvote 0
How about
Code:
Sub Copy()
Dim x As Workbook
Dim Rng As Range
Set Rng = Range("A2", Range("A" & Rows.Count).End(xlUp).Offset(, 2))
Set x = Workbooks.Open("O:\Public\Ads\1\V2.xlsm")

Rng.Copy x.Sheets("Input").Range("B2")
End Sub

Excellent that works, thanks Fluff!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,553
Messages
6,125,483
Members
449,233
Latest member
Deardevil

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