Copy Paste data from one source document to multiple excel documents

babar2019

Board Regular
Joined
Jun 21, 2019
Messages
93
Hi,

I have an excel which is the source document containing the following data.

Column A - Process Name
Column B - Date
Column C-G - data

I want the code to

read the Process Name in column A (source) and open respective excel document (destination)
read the date in Column B (source) and go to that respective tab (destination)
copy values A through G columns (source) and paste in the last empty row in the document (destination).

For example, if the source document column A reads SIGNAPAY, Column B reads 070819 then the code should open an excel called SIGNAPAY, go to the 07 19 tab and go to the last empty row and copy columns A-G from the source document and paste it here and close the workbook.

Can somebody please help me with the code.

Thank you in advance
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
This will work only if your filenames in Column A are in the same directory as your source workbook.
Code:
Sub t()
Dim c As Range, sh As Worksheet, wb As Workbook, tb As String, fPath As String
fPath = ThisWorkbook.Path & "\"
Set sh = ActiveSheet
    For Each c In sh.Range("A2", sh.Cells(Rows.Count, 1).End(xlUp))
        Set wb = Workbooks.Open(fPath & c.Value & ".xlsx")
            tb = CStr(Left(c.Offset(, 1), 2) & " " & Right(c.Offset(, 1), 2))
            Intersect(wb.Sheets(tb).UsedRange, wb.Sheets(tb).Range("A:G")).Copy _
            sh.Cells(Rows.Count, 1).End(xlUp)(2)
            wb.Close False
    Next
End Sub
Because you are working with dates, and the configuration of the date in the source workbook is not the same as the sheet tab name date, you might encounter a problem with "Subscript out of Range" errors. I have tried to accomodate that, but without seeing your worksheets, it might not be enough. You can try it and post back with the results.
 
Upvote 0
Hi JLGWhiz,

Thanks for your response. This didn't work and giving 'out of subscript range' errors.

The column A is not directly the file name but just the name of the process.

All I'm trying to do is, See if column A has the word 'Signapay' then open a workbook called In Process SIGNAPAY, see how many rows in column A have the word signapay and copy columns A:G and paste it into the In Process SIGNAPAY workbook.
 
Upvote 0
You need to post a facimile of your worksheets, or a link to your files on a share server. I don't understand how your data in column A is configured.
 
Upvote 0
Please see below. Copy pasted directly from excel.

[TABLE="width: 1031"]
<colgroup><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]DMTITL[/TD]
[TD]DHACCT[/TD]
[TD]DHDATE[/TD]
[TD]DHDATC[/TD]
[TD]DHITC[/TD]
[TD]DHAMT[/TD]
[TD]DESC1[/TD]
[TD]DESC2[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019189[/TD]
[TD="align: right"]70819[/TD]
[TD="align: right"]55[/TD]
[TD="align: right"]259[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019189[/TD]
[TD="align: right"]70819[/TD]
[TD="align: right"]55[/TD]
[TD="align: right"]499[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019189[/TD]
[TD="align: right"]70819[/TD]
[TD="align: right"]55[/TD]
[TD="align: right"]2795.81[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019189[/TD]
[TD="align: right"]70819[/TD]
[TD="align: right"]55[/TD]
[TD="align: right"]6000[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019189[/TD]
[TD="align: right"]70819[/TD]
[TD="align: right"]55[/TD]
[TD="align: right"]6500[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019190[/TD]
[TD="align: right"]70919[/TD]
[TD="align: right"]55[/TD]
[TD="align: right"]114[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019191[/TD]
[TD="align: right"]71019[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]834.47[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019191[/TD]
[TD="align: right"]71019[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]1590.7[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019191[/TD]
[TD="align: right"]71019[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]2609.02[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019191[/TD]
[TD="align: right"]71019[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]3294.32[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019191[/TD]
[TD="align: right"]71019[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]4632.49[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
[TR]
[TD]SIGNAPAY LTD IN PROCESS ACCOUN[/TD]
[TD]xxxxxxxxxx[/TD]
[TD="align: right"]2019191[/TD]
[TD="align: right"]71019[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]6667.57[/TD]
[TD]Testing[/TD]
[TD]Test Company[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
I am sorry, but there appears to be a lot of inconsistency between the original post and the subsequent posts related to the details of the data and files. I cannot decipher the actual requirement nor how to determine the files and worksheets. Perhaps someone else can do better.
 
Upvote 0
Hi JLGWhiz,

Sorry If the post was confusing.

So the data you see above is the source document.

I want VBA to see if the document has the word 'SIGNAPAY' in column A, if true then open a document called 'In process SIGNAPAY.xlsx' from a location.
Format the Date in Column C of the source to MM YYYY and go into the tab which matches with the MM YYYY of the source column with the 'In Process SIGNAPAY.xlsx' workbook.
Paste values into the new cells 'In Process SIGNAPAY.xlsx' workbook for all the rows that have the word SIGNAPAY through columns A:G.

I hope I was clear :)
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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