copy data from one workbook to another-unknown problem

dharsana

Board Regular
Joined
Sep 7, 2002
Messages
58
hi
I am having a file "part".The data in "part" file is to be appended to another file "part-master" in the empty row.
part.xls
ABCDEFGH
1SLOTNOYEARNAMESTAFFNOBRANCHDESIGCODENOPROGRAM
2200225September-02KUMAR25789BANG,JAYANAGARCLERK1151ALPM-W
3200225Sep-02MOHAN58963BANG,BASAVANAGUDISPL.AAST1151ALPM-W
4200226Sep-02MANI25369KALAKKODOFFICER1152ALPM-O
5200226Nov-02MINI52698MANJERIOFFICER1152ALPM-O
6200227Nov-02SEKAR25897KOPPALMANAGER1198B2K-D-O
7200227Nov-02VENU45263HARIHARMANAGER1198B2K-D-O
8200225September-02KUMAR25789BANG,JAYANAGARCLERK1151ALPM-W
9200225Sep-02MOHAN58963BANG,BASAVANAGUDISPL.AAST1151ALPM-W
10200226Sep-02MANI25369KALAKKODOFFICER1152ALPM-O
Sheet1
part.xls
ABCDEFGH
1SLOTNOYEARNAMESTAFFNOBRANCHDESIGCODENOPROGRAM
2200225September-02KUMAR25789BANG,JAYANAGARCLERK1151ALPM-W
3200225Sep-02MOHAN58963BANG,BASAVANAGUDISPL.AAST1151ALPM-W
4200226Sep-02MANI25369KALAKKODOFFICER1152ALPM-O
5200226Nov-02MINI52698MANJERIOFFICER1152ALPM-O
6200227Nov-02SEKAR25897KOPPALMANAGER1198B2K-D-O
7200227Nov-02VENU45263HARIHARMANAGER1198B2K-D-O
8200225September-02KUMAR25789BANG,JAYANAGARCLERK1151ALPM-W
9200225Sep-02MOHAN58963BANG,BASAVANAGUDISPL.AAST1151ALPM-W
10200226Sep-02MANI25369KALAKKODOFFICER1152ALPM-O
Sheet1



I have put the follwing macro in part file and it works upto showing the message box with the empty row.Afterwards it is not copying the data to "part-master".If I change the destination file as Thisworkbook it is copying in the "part" file correctly and if I change the destination file to "part-master" it is not doing anything.
Any body can tell what mistake I am doing
Sub Macro2()
' Macro by sys
'
Dim LastRow As Long

'work with target workbook, changed to Book2 for testing
On Error Resume Next
Workbooks.Open Filename:="c:my documentspart-master"
With Application.Workbooks("c:mydocumentspart-master")

'find next blank row in target workbook
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End If
LastRow = LastRow + 1
MsgBox LastRow
End With
ThisWorkbook.Sheets(1).Rows("2:22").Copy _
Destination:=Workbooks("c:my documentspart-master").Sheets(1).Cells(LastRow, 1)
End Sub
Thanks in advance
dharsana
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this

Sub Test()
Dim LastRow As Long
'work with target workbook, changed to Book2 for testing
On Error Resume Next
Workbooks.Open FileName:="c:\my documents\part-master"
On Error GoTo 0
'find next blank row in target workbook
If WorksheetFunction.CountA(Cells) > 0 Then
LastRow = Workbooks("c:\my documents\part-master").Sheets(1). _
Cells(65536, 1).Offset(xlUp).Rows + 1
Range(Workbooks("c:\my documents\part-master").Sheets(1).Cells(LastRow, 1)).Value = _
ThisWorkbook.Sheets(1).Rows("2:22").Copy
End If
End Sub

By the way you did not cancel your on error, so if there was an error later it would not show.
 
Upvote 0
hi john,

Thanks for the immediatereply .I copied your macro into "part" file (I do not understand why there are two forward slashes in filename(pathname) and I modified it to single slashes.If I execute the macro it gives syntax error at the following line

lastrow=workbooks("c:my documentspart-master").sheets(1)_

Any further help

dharsana
 
Upvote 0

Forum statistics

Threads
1,226,223
Messages
6,189,710
Members
453,566
Latest member
ariestattle

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