Combine multiple csv files by rows number

Enna

New Member
Joined
Oct 5, 2021
Messages
41
Office Version
  1. 2010
Platform
  1. Windows
I have multiple about 300 csv files (each have different headings and the number of records is the same -about 80,000), how can I combine all those 300 csv files by row numbers and make one final csv file with about 80,000 records and all the variables from each 300 files using VBA? Thank you
 
Book2
ABCDEFGHIJKLMNOPQRSTU
1REDCap IDSubmitter AffiliationPoint of Care affiliationIf Other, please provide affiliationSubmitter Full NameName of SubmitterNotification DateNotification TimeIs this a:Was DC Health Notified through DGMQ / Epi-X?DGMQ ID / Epi-X IDPlease select mode of travel where exposure could have occurred based on DGMQ notificationFlight NumberCruise NamePassport CountryPassport NumberKey contact related to this person included in DGMQ Date arrived in U.S.Last possible exposure date (Day 0)Date Monitoring by DC Health Started (may not be Date for Day 1)
214/1/2020ZZ HealthSomeone Someone########15:30<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>No
333/26/2020ZZ HealthSomeone Someone########9:39<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>No
464/6/2020ZZ HealthSomeone SomeoneSomeone S<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>No
Sheet1
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Book2
ABCDEFGHIJKLMNOPQRSTU
1REDCap IDMonitoring end date (14 days after [exposure_end_dt] )How was DC health notified of the case?Caller/Provider FIRST nameCaller/Provider LAST nameCaller/Provider Phone NumberCaller/Provider EmailCaller/Provider Affiliation/OrganizationCollege/University/School Name:If other, please specifyFIRST nameLAST nameMIDDLE IntialDate of birth (in the format of MM-DD-YYYY)Age (years)Patient sexPlease describe other sex:Patient sex at birthPatient currently pregnant?How many weeks pregnant?Estimated due date
21Healthcare Provider / Redcap / ELRSomeoneSome202000000someone@someth.orgSomeone's SomewheneNSOemcNpepmfe########12Male
33Healthcare Provider / Redcap / ELRSomeSomething202-000-000MW jwpjdmcevomoeNCPmprC########55Male
46PatientcmepfmwpefMEPmce########8FemaleNo
Sheet1
 
Last edited:
Upvote 0
Book2
ABCDEFGHIJKLMNOPQRSTU
1REDCap IDMonitoring end date (14 days after [exposure_end_dt] )How was DC health notified of the case?Caller/Provider FIRST nameCaller/Provider LAST nameCaller/Provider Phone NumberCaller/Provider EmailCaller/Provider Affiliation/OrganizationCollege/University/School Name:If other, please specifyFIRST nameLAST nameMIDDLE IntialDate of birth (in the format of MM-DD-YYYY)Age (years)Patient sexPlease describe other sex:Patient sex at birthPatient currently pregnant?How many weeks pregnant?Estimated due date
21Healthcare Provider / Redcap / ELRSomeoneSome202000000someone@someth.orgSomeone's SomewheneNSOemcNpepmfe########12Male
33Healthcare Provider / Redcap / ELRSomeSomething202-000-000MW jwpjdmcevomoeNCPmprC########55Male
46PatientcmepfmwpefMEPmce########8FemaleNo
Sheet1

For the final combined table, first order should be from first csv file (tmp_1) followed by next order tmp_2, tmp_3 etc. and redcap ID should be only in first column not from each table. Thank you.
Note: I have about csv tables (tmp_1 ....tmp_24).
 
Upvote 0
I see no ID in the Capture1.png -- since you are not showing us a workable file, I will offer up this video so that you can do this on your own. I am out.

Thank you. This video is nice but not helpful at all. I provide the tables. Could you work on the tables. Thank you.
 
Upvote 0
I see no ID in the Capture1.png -- since you are not showing us a workable file, I will offer up this video so that you can do this on your own. I am out.

Hello.
The first table is this:
test.xlsx
ABCDEFGHIJKLMNOPQRSTU
1REDCap IDSubmitter AffiliationPoint of Care affiliationIf Other, please provide affiliationSubmitter Full NameName of SubmitterNotification DateNotification TimeIs this a:Was DC Health Notified through DGMQ / Epi-X?DGMQ ID / Epi-X IDPlease select mode of travel where exposure could have occurred based on DGMQ notificationFlight NumberCruise NamePassport CountryPassport NumberKey contact related to this person included in DGMQ Date arrived in U.S.Last possible exposure date (Day 0)Date Monitoring by DC Health Started (may not be Date for Day 1)
214/1/2020ZZ HealthSomeone Someone########15:30<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>No
333/26/2020ZZ HealthSomeone Someone########9:39<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>No
464/6/2020ZZ HealthSomeone SomeoneSomeone S<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>No
Sheet1



The next table is this:
test.xlsx
ABCDEFGHIJKLMNOPQRSTU
1REDCap IDMonitoring end date (14 days after [exposure_end_dt] )How was DC health notified of the case?Caller/Provider FIRST nameCaller/Provider LAST nameCaller/Provider Phone NumberCaller/Provider EmailCaller/Provider Affiliation/OrganizationCollege/University/School Name:If other, please specifyFIRST nameLAST nameMIDDLE IntialDate of birth (in the format of MM-DD-YYYY)Age (years)Patient sexPlease describe other sex:Patient sex at birthPatient currently pregnant?How many weeks pregnant?Estimated due date
21Healthcare Provider / Redcap / ELRSomeNnnr2020000000grafvr@fzsb.orgSomemsb gb ggi' fvrvrbxdtft########12Male
33Healthcare Provider / Redcap / ELRSomesNobt202-000-0000KCmrmv rdvebrdygchrdtxfgnC########55Male
46Patientfgnndrxftj########8FemaleNo
Sheet1



Final desired combined table is below:
test.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAO
1REDCap IDSubmitter AffiliationPoint of Care affiliationIf Other, please provide affiliationSubmitter Full NameName of SubmitterNotification DateNotification TimeIs this a:Was DC Health Notified through DGMQ / Epi-X?DGMQ ID / Epi-X IDPlease select mode of travel where exposure could have occurred based on DGMQ notificationFlight NumberCruise NamePassport CountryPassport NumberKey contact related to this person included in DGMQ Date arrived in U.S.Last possible exposure date (Day 0)Date Monitoring by DC Health Started (may not be Date for Day 1)Monitoring end date (14 days after [exposure_end_dt] )How was DC health notified of the case?Caller/Provider FIRST nameCaller/Provider LAST nameCaller/Provider Phone NumberCaller/Provider EmailCaller/Provider Affiliation/OrganizationCollege/University/School Name:If other, please specifyFIRST nameLAST nameMIDDLE IntialDate of birth (in the format of MM-DD-YYYY)Age (years)Patient sexPlease describe other sex:Patient sex at birthPatient currently pregnant?How many weeks pregnant?Estimated due date
214/1/2020ZZ HealthSomeone Someone########15:30<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>NoHealthcare Provider / Redcap / ELRSomeNnnr2020000000grafvr@fzsb.orgSomemsb gb ggi' fvrvrbxdtft########12Male
333/26/2020ZZ HealthSomeone Someone########9:39<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>NoHealthcare Provider / Redcap / ELRSomesNobt202-000-0000KCmrmv rdvebrdygchrdtxfgnC########55Male
464/6/2020ZZ HealthSomeone SomeoneSomeone S<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>NoPatientfgnndrxftj########8FemaleNo
Sheet1




Those are just 2 sample tables. There are 24 csv files. Thank you so much!
 
Upvote 0
With Power Query which is available to you as a free add-in for XL2010 your can merge (outer join) your two tables on the common ID field.

Power Query:
let
    Source = Table.NestedJoin(Table1, {"REDCap ID"}, Table2, {"REDCap ID"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Column1", "Submitter Affiliation", "Point of Care affiliation", "If Other, please provide affiliation", "Submitter Full Name", "Name of Submitter", "Notification Date", "Notification Time", "Is this a:", "Was DC Health Notified through DGMQ / Epi-X?", "DGMQ ID / Epi-X ID", "Please select mode of travel where exposure could have occurred based on DGMQ notification", "Flight Number", "Cruise Name", "Passport Country", "Passport Number", "Key contact related to this person included in DGMQ ", "Date arrived in U.S.", "Last possible exposure date (Day 0)", "Date Monitoring by DC Health Started (may not be Date for Day 1)", "Monitoring end date (14 days after [exposure_end_dt]  )", "How was DC health notified of the case?", "Caller/Provider FIRST name", "Caller/Provider LAST name", "Caller/Provider Phone Number", "Caller/Provider Email", "Caller/Provider Affiliation/Organization", "College/University/School Name:", "If other, please specify", "FIRST name", "LAST name", "MIDDLE Intial", "Date of birth (in the format of MM-DD-YYYY)", "Age (years)", "Patient sex", "Please describe other sex:", "Patient sex at birth", "Patient currently pregnant?", "How many weeks pregnant?", "Estimated due date"}, {"Column1", "Submitter Affiliation", "Point of Care affiliation", "If Other, please provide affiliation", "Submitter Full Name", "Name of Submitter", "Notification Date", "Notification Time", "Is this a:", "Was DC Health Notified through DGMQ / Epi-X?", "DGMQ ID / Epi-X ID", "Please select mode of travel where exposure could have occurred based on DGMQ no", "Flight Number", "Cruise Name", "Passport Country", "Passport Number", "Key contact related to this person included in DGMQ ", "Date arrived in U.S.", "Last possible exposure date (Day 0)", "Date Monitoring by DC Health Started (may not be Date for Day 1)", "Monitoring end date (14 days after [exposure_end_dt]  ).1", "How was DC health notified of the case?.1", "Caller/Provider FIRST name.1", "Caller/Provider LAST name.1", "Caller/Provider Phone Number.1", "Caller/Provider Email.1", "Caller/Provider Affiliation/Organization.1", "College/University/School Name:.1", "If other, please specify.1", "FIRST name.1", "LAST name.1", "MIDDLE Intial.1", "Date of birth (in the format of MM-DD-YYYY).1", "Age (years).1", "Patient sex.1", "Please describe other sex:.1", "Patient sex at birth.1", "Patient currently pregnant?.1", "How many weeks pregnant?.1", "Estimated due date.1"})
in
    #"Expanded Table2"

Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBI
1REDCap IDMonitoring end date (14 days after [exposure_end_dt] )How was DC health notified of the case?Caller/Provider FIRST nameCaller/Provider LAST nameCaller/Provider Phone NumberCaller/Provider EmailCaller/Provider Affiliation/OrganizationCollege/University/School Name:If other, please specifyFIRST nameLAST nameMIDDLE IntialDate of birth (in the format of MM-DD-YYYY)Age (years)Patient sexPlease describe other sex:Patient sex at birthPatient currently pregnant?How many weeks pregnant?Estimated due dateColumn1Submitter AffiliationPoint of Care affiliationIf Other, please provide affiliationSubmitter Full NameName of SubmitterNotification DateNotification TimeIs this a:Was DC Health Notified through DGMQ / Epi-X?DGMQ ID / Epi-X IDPlease select mode of travel where exposure could have occurred based on DGMQ noFlight NumberCruise NamePassport CountryPassport NumberKey contact related to this person included in DGMQ Date arrived in U.S.Last possible exposure date (Day 0)Date Monitoring by DC Health Started (may not be Date for Day 1)Monitoring end date (14 days after [exposure_end_dt] ).1How was DC health notified of the case?.1Caller/Provider FIRST name.1Caller/Provider LAST name.1Caller/Provider Phone Number.1Caller/Provider Email.1Caller/Provider Affiliation/Organization.1College/University/School Name:.1If other, please specify.1FIRST name.1LAST name.1MIDDLE Intial.1Date of birth (in the format of MM-DD-YYYY).1Age (years).1Patient sex.1Please describe other sex:.1Patient sex at birth.1Patient currently pregnant?.1How many weeks pregnant?.1Estimated due date.1
21Healthcare Provider / Redcap / ELRSomeNnnr2020000000grafvr@fzsb.orgSomemsb gb ggi' fvrvrbxdtft3922412Male4/1/2020ZZ HealthSomeone Someone439050.645833333<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>NoHealthcare Provider / Redcap / ELRSomeNnnr2020000000grafvr@fzsb.orgSomemsb gb ggi' fvrvrbxdtft3922412Male
33Healthcare Provider / Redcap / ELRSomesNobt202-000-0000KCmrmv rdvebrdygchrdtxfgnC2346255Male3/26/2020ZZ HealthSomeone Someone439060.402083333<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>NoHealthcare Provider / Redcap / ELRSomesNobt202-000-0000KCmrmv rdvebrdygchrdtxfgnC2346255Male
46Patientfgnndrxftj408308FemaleNo4/6/2020ZZ HealthSomeone SomeoneSomeone S<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>NoPatientfgnndrxftj408308FemaleNo
Merge1


If you want to consolidate all the csv files then do this for each and then in Power Query, append each. Then when you make any change to one, it will be updated in the "Master" upon a Refresh. It may be a bit laborious to set up, but will be almost instantaneous when updated.
 
Upvote 0
With Power Query which is available to you as a free add-in for XL2010 your can merge (outer join) your two tables on the common ID field.

Power Query:
let
    Source = Table.NestedJoin(Table1, {"REDCap ID"}, Table2, {"REDCap ID"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Column1", "Submitter Affiliation", "Point of Care affiliation", "If Other, please provide affiliation", "Submitter Full Name", "Name of Submitter", "Notification Date", "Notification Time", "Is this a:", "Was DC Health Notified through DGMQ / Epi-X?", "DGMQ ID / Epi-X ID", "Please select mode of travel where exposure could have occurred based on DGMQ notification", "Flight Number", "Cruise Name", "Passport Country", "Passport Number", "Key contact related to this person included in DGMQ ", "Date arrived in U.S.", "Last possible exposure date (Day 0)", "Date Monitoring by DC Health Started (may not be Date for Day 1)", "Monitoring end date (14 days after [exposure_end_dt]  )", "How was DC health notified of the case?", "Caller/Provider FIRST name", "Caller/Provider LAST name", "Caller/Provider Phone Number", "Caller/Provider Email", "Caller/Provider Affiliation/Organization", "College/University/School Name:", "If other, please specify", "FIRST name", "LAST name", "MIDDLE Intial", "Date of birth (in the format of MM-DD-YYYY)", "Age (years)", "Patient sex", "Please describe other sex:", "Patient sex at birth", "Patient currently pregnant?", "How many weeks pregnant?", "Estimated due date"}, {"Column1", "Submitter Affiliation", "Point of Care affiliation", "If Other, please provide affiliation", "Submitter Full Name", "Name of Submitter", "Notification Date", "Notification Time", "Is this a:", "Was DC Health Notified through DGMQ / Epi-X?", "DGMQ ID / Epi-X ID", "Please select mode of travel where exposure could have occurred based on DGMQ no", "Flight Number", "Cruise Name", "Passport Country", "Passport Number", "Key contact related to this person included in DGMQ ", "Date arrived in U.S.", "Last possible exposure date (Day 0)", "Date Monitoring by DC Health Started (may not be Date for Day 1)", "Monitoring end date (14 days after [exposure_end_dt]  ).1", "How was DC health notified of the case?.1", "Caller/Provider FIRST name.1", "Caller/Provider LAST name.1", "Caller/Provider Phone Number.1", "Caller/Provider Email.1", "Caller/Provider Affiliation/Organization.1", "College/University/School Name:.1", "If other, please specify.1", "FIRST name.1", "LAST name.1", "MIDDLE Intial.1", "Date of birth (in the format of MM-DD-YYYY).1", "Age (years).1", "Patient sex.1", "Please describe other sex:.1", "Patient sex at birth.1", "Patient currently pregnant?.1", "How many weeks pregnant?.1", "Estimated due date.1"})
in
    #"Expanded Table2"

Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBI
1REDCap IDMonitoring end date (14 days after [exposure_end_dt] )How was DC health notified of the case?Caller/Provider FIRST nameCaller/Provider LAST nameCaller/Provider Phone NumberCaller/Provider EmailCaller/Provider Affiliation/OrganizationCollege/University/School Name:If other, please specifyFIRST nameLAST nameMIDDLE IntialDate of birth (in the format of MM-DD-YYYY)Age (years)Patient sexPlease describe other sex:Patient sex at birthPatient currently pregnant?How many weeks pregnant?Estimated due dateColumn1Submitter AffiliationPoint of Care affiliationIf Other, please provide affiliationSubmitter Full NameName of SubmitterNotification DateNotification TimeIs this a:Was DC Health Notified through DGMQ / Epi-X?DGMQ ID / Epi-X IDPlease select mode of travel where exposure could have occurred based on DGMQ noFlight NumberCruise NamePassport CountryPassport NumberKey contact related to this person included in DGMQ Date arrived in U.S.Last possible exposure date (Day 0)Date Monitoring by DC Health Started (may not be Date for Day 1)Monitoring end date (14 days after [exposure_end_dt] ).1How was DC health notified of the case?.1Caller/Provider FIRST name.1Caller/Provider LAST name.1Caller/Provider Phone Number.1Caller/Provider Email.1Caller/Provider Affiliation/Organization.1College/University/School Name:.1If other, please specify.1FIRST name.1LAST name.1MIDDLE Intial.1Date of birth (in the format of MM-DD-YYYY).1Age (years).1Patient sex.1Please describe other sex:.1Patient sex at birth.1Patient currently pregnant?.1How many weeks pregnant?.1Estimated due date.1
21Healthcare Provider / Redcap / ELRSomeNnnr2020000000grafvr@fzsb.orgSomemsb gb ggi' fvrvrbxdtft3922412Male4/1/2020ZZ HealthSomeone Someone439050.645833333<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>NoHealthcare Provider / Redcap / ELRSomeNnnr2020000000grafvr@fzsb.orgSomemsb gb ggi' fvrvrbxdtft3922412Male
33Healthcare Provider / Redcap / ELRSomesNobt202-000-0000KCmrmv rdvebrdygchrdtxfgnC2346255Male3/26/2020ZZ HealthSomeone Someone439060.402083333<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>NoHealthcare Provider / Redcap / ELRSomesNobt202-000-0000KCmrmv rdvebrdygchrdtxfgnC2346255Male
46Patientfgnndrxftj408308FemaleNo4/6/2020ZZ HealthSomeone SomeoneSomeone S<font color= 'red'>Person under investigation (PUI; symptomatic/asymptomatic)</font>NoPatientfgnndrxftj408308FemaleNo
Merge1


If you want to consolidate all the csv files then do this for each and then in Power Query, append each. Then when you make any change to one, it will be updated in the "Master" upon a Refresh. It may be a bit laborious to set up, but will be almost instantaneous when updated.
Thank you. Can it be a vba code without listing all column names from each csv file? Since some column does not have a header too and there are about 600 variables.
 
Upvote 0
You will have to wait for someone with more VBA skills than me. I cannot address that issue. I have provided you with what I have available in my skill bank. I will be leaving this thread for others since you are looking for a different solution.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,683
Members
449,116
Latest member
HypnoFant

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