|
-
Nov 17th, 2011, 05:16 AM
#1
Re: [Excel] Copy data from specific cells to another workbook
As a note, is it possible to use a network patch to open the closed source?
assuming this means PATH, then yes
so if the last row was Number 2 it needs to copy on row 3
try like
vb Code:
nextrow = wbkdes.Sheets("Récup Info").cells(wbkdes.Sheets("Récup Info").rows.count, 1).end(xlup).row + 1 wbkdes.Sheets("Récup Info").Cells(nextrow, 1) = wbksour.Sheets("Bon de Travaux").Cells(28, 16) ' rest of code to fill cells
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 17th, 2011, 05:53 AM
#2
Thread Starter
New Member
Re: [Excel] Copy data from specific cells to another workbook
 Originally Posted by westconn1
assuming this means PATH, then yes
Yes, it was path and not patch.
 Originally Posted by westconn1
try like
vb Code:
nextrow = wbkdes.Sheets("Récup Info").cells(wbkdes.Sheets("Récup Info").rows.count, 1).end(xlup).row + 1
wbkdes.Sheets("Récup Info").Cells(nextrow, 1) = wbksour.Sheets("Bon de Travaux").Cells(28, 16)
' rest of code to fill cells
Ok, with this the code is working like clockwork.
Here's the overall code for others:
Code:
Private Sub Button_Copy_Click()
Dim wbksour As Workbook
Dim wbkdes As Workbook
Dim strFirstFile As String
Dim strSecondFile As String
strFirstFile = "Schéma récap MG.xls" 'Use the opened document as source
strSecondFile = "\\prc2507et001\IRFSSMP_31\IRFSS\_MAINTENANCE\Récup Info.xls" 'Path for destination document
Set wbksour = Workbooks(strFirstFile)
Set wbkdes = Workbooks.Open(strSecondFile)
nextrow = wbkdes.Sheets("Récup Info").Cells(wbkdes.Sheets("Récup Info").Rows.Count, 1).End(xlUp).Row + 1
wbkdes.Sheets("Récup Info").Cells(nextrow, 1) = wbksour.Sheets("Bon de Travaux").Cells(28, 16) 'Copies P28 into Cell A2 of wbkdes.Sheets("Récup Info")
wbkdes.Sheets("Récup Info").Cells(nextrow, 2) = wbksour.Sheets("Bon de Travaux").Cells(6, 6) 'Copies F6 into Cell B2 of wbkdes.Sheets("Récup Info")
wbkdes.Sheets("Récup Info").Cells(nextrow, 3) = wbksour.Sheets("Bon de Travaux").Cells(8, 6) 'Copies F8 into Cell C2 of wbkdes.Sheets("Récup Info")
wbkdes.Sheets("Récup Info").Cells(nextrow, 4) = wbksour.Sheets("Bon de Travaux").Cells(10, 6) 'Copies F10 into Cell D2 of wbkdes.Sheets("Récup Info")
wbkdes.Sheets("Récup Info").Cells(nextrow, 5) = wbksour.Sheets("Bon de Travaux").Cells(12, 6) 'Copies F12 into Cell E2 of wbkdes.Sheets("Récup Info")
wbkdes.Sheets("Récup Info").Cells(nextrow, 6) = wbksour.Sheets("Bon de Travaux").Cells(14, 6) 'Copies F14 into Cell F2 of wbkdes.Sheets("Récup Info")
wbkdes.Save 'Save the Destination worksheet
wbkdes.Close 'Close the Destination worksheet
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|