Copying latest ROW in one excel file to first ROW in another excel file using VBA

snizami

New member
Local time
Today, 15:09
Joined
Feb 13, 2013
Messages
2
Hi Guys, I'm trying the following code but it returns with "Invalid qualifier" for "LastRow.Cpy", any suggestions?

Private Sub Rect143_Click()
Dim LastRow As Long
Dim FirstRow As Long

Open "C:\temp\TESTGC.XLS" For Input As #1 'open 1st excel file
LastRow = ActiveSheet.UsedRange.Rows.Count 'capture the lastest row
LastRow.Copy 'copy the latset row
FirstRow = LastRow 'assign it other variable
Open "C:\temp\TESTGC1.XLS" For Input As #2 'open 2nd excel file
FirstRow.Paste 'paste it to first row in 2nd excel file


Close #1 'Close 1st file
Close #2 'Close 2nd file
End Sub

Best Regards
 
You have tried to copy and paste a row number and not the values. That is why Excel has errored.

Try this:
Code:
Private Sub Rect143_Click()
Dim LastRow As Long
Dim FirstRow As Long

Open "C:\temp\TESTGC.XLS" For Input As #1 'open 1st excel file
LastRow = ActiveSheet.UsedRange.Rows.Count 'capture the lastest row
Cells(LastRow, 1).EntireRow.Copy 'copy the latset row

Open "C:\temp\TESTGC1.XLS" For Input As #2 'open 2nd excel file
'FirstRow.Paste 'paste it to first row in 2nd excel file
FirstRow = ActiveSheet.UsedRange.Rows.Count 'capture the lastest row
Cells(FirstRow, 1).Select
ActiveSheet.Paste

Close #1 'Close 1st file
Close #2 'Close 2nd file
End Sub
 

Users who are viewing this thread

Back
Top Bottom