Copy from one workbook to another

NewbieMike

New Member
Joined
May 29, 2015
Messages
4
Hi all! I need to copy a undefined number of rows(my range would always be from "$a$4 to n??") that i need to copy from one worksheet from one workbook into the first available cell on another sheet on a different workbook. I am new to VBA and am having problems getting this to work correctly. I found the below code but it copys more than just the rows that have actual data in them and doesn't paste correctly on the destination worksheet. Can anybody help? Does this make any sense? Thank you all! :confused:

Sub CopynPasteWrkBk()
Dim InputFile As Workbook
Dim OutputFile As Workbook
Dim Inputpath As String
Dim Outputpath As String '

Set InputFile = ActiveWorkbook
Set OutputFile = Workbooks.Open("C:\Users\john\Desktop\MVR REPORT\BOOK2.XLSX")


InputFile.Sheets("TRACKER").Activate
InputFile.Sheets("TRACKER").Range("A4:N4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

OutputFile.Sheets("TRACKER").Activate
OutputFile.Sheets("TRACKER").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues


OutputFile.Close savechanges:=True

MsgBox "Data Successfully Logged"

End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

yky

Well-known Member
Joined
Jun 7, 2011
Messages
1,881
Office Version
  1. 2010
Platform
  1. Windows
What is the range you want to copy and where to paste to?
 
Upvote 0

NewbieMike

New Member
Joined
May 29, 2015
Messages
4
Hi yky!

I want to copy from workbook(active workbook) sheet(Tracker) range(A4:N??) and paste to workbook(book2) sheet(Tracker) range(first available cell{starting in column A}. Thanks!
 
Upvote 0

yky

Well-known Member
Joined
Jun 7, 2011
Messages
1,881
Office Version
  1. 2010
Platform
  1. Windows
What is N?? and what is the first available cell in A? I gather from your code that N?? is the first blank cell down from N4 and the first available cell in column A is the first blank cell down from A4. If so, try the following code. If not, try changing the cell address to suit what you want.

Code:
InputFile.Sheets("TRACKER").Range(InputFile.Sheets("TRACKER").Cells(4, 1), _
InputFile.Sheets("TRACKER").Cells(4, 14).End(xlDown)).Copy
OutputFile.Sheets("TRACKER").Cells(1, 1).End(xlDown).PasteSpecial Paste:=xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,195,582
Messages
6,010,581
Members
441,557
Latest member
Jbest23

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
Top