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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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.

DMTITLDHACCTDHDATEDHDATCDHITCDHAMTDESC1DESC2
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx20191897081955259TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx20191897081955499TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx201918970819552795.81TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx201918970819556000TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx201918970819556500TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx20191907091955114TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx20191917101918834.47TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx201919171019181590.7TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx201919171019182609.02TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx201919171019183294.32TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx201919171019184632.49TestingTest Company
SIGNAPAY LTD IN PROCESS ACCOUNxxxxxxxxxx201919171019186667.57TestingTest Company

<colgroup><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 
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,214,813
Messages
6,121,705
Members
449,048
Latest member
81jamesacct

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