Merge two table from different csv files

Soly_90

New Member
Joined
Sep 4, 2024
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hello ,
I am still beginner in using macro vba and I need a help .
I have two different csv file .
I want the user to enter the path file of the csv file to use as input in the script
This csv file has only one sheet called data ,that include one table with different columns .

The second csv file contains sheet called source
,include only one table .

I want to merge this table from first csv file with the table from the second csv file .

(first csv file (user input ) contains always column called target and the second csv file contains also target column )
Both of them has target column name
I need only to merge the rows that contains same value in target column and ignore the rest rows .


I would like to have like window ,that allow user to enter the file path of excel file and also the user enter folder path of csv file
And button to run the script

Could you help me ?
Thanks in advance
 
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:


There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Sorry, but I am not familiar with the download site and it is requiring me to sign up. No thanks. Good Luck. I'm out unless you use MrE's XL2BB functionality. Instructions are on the site. Read the forum rules and help.
I think u mentioned above to upload in drop box or other .
But anyway ,it is not requiring to sign up .
I will look , how it XL2BB works .
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:


There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Sorry but I am new .i do not know about your rules .
Will you want to help me or give advice to solve the issue ?
 
Upvote 0
Then please read them now. They are the same in this respect as the other forums you have posted on.
I can delete the posts at other forums .if I have to do it because of your rules .
Will my post still here ?
Could I get some advices or solution of my problem ?
Thanks
 
Last edited:
Upvote 0
I can delete the posts at other forums .if I have to do it because of your rules .

If you actually read the rules, as I have asked, you will see the answer to that (which is no).
 
Upvote 0
I could download the files.

So you would proceed like this:

1. Copy Data csv files in one folder, and Source csv files in another folder.
2. In an new excel file, go to the menu "Data/Get & Transform Data/Get Data/From File/From Folder"
1725621892231.png


Select Data folder. Click on Transform Data
1725621963473.png

3. In the power query editor click on the icon of the first column:
1725622052274.png

and click ok. Select Source.Name column and remove it.
You should see this:

1725622134149.png


4. (Still in Power Query Editor) click on menu "New Query/New source/File/Folder"
1725622261523.png


Select Source folder and then the same steps as before.
You should see this:

1725622347868.png


Now select column "Result" and go to menu "Home/Transform/Split Column/By Delimiter", select "Semicolon" and "Each occurence of the delimiter", click ok. You should see this:

1725623628669.png


5. Go to menu "Combine/Merge Queries/Merge Queries as New"
1725622470151.png


Select Data in the first, and Source in the second. Then click the target column in both. Below select "Inner" as the Join Kind:

1725623550785.png


You will get this:

1725623589249.png


Click on the marked icon and uncheck target from the list, and uncheck "Use original column name as prefix" (no neccesary).
Then you can rename and reorder the columns as needed.

6. Last remove the target column (right click, remove). And click menu Close&Load. You will get 3 new sheets, Data, Source and Merge1. You can delete sheets Data and Source if you like. In Merge1 you should get the result:

1725623705080.png



Let me know if this works for you or if you need any assistance.
 
Upvote 0

I could download the files.

So you would proceed like this:

1. Copy Data csv files in one folder, and Source csv files in another folder.
2. In an new excel file, go to the menu "Data/Get & Transform Data/Get Data/From File/From Folder"
View attachment 116490

Select Data folder. Click on Transform Data View attachment 116491
3. In the power query editor click on the icon of the first column:
View attachment 116492
and click ok. Select Source.Name column and remove it.
You should see this:

View attachment 116493

4. (Still in Power Query Editor) click on menu "New Query/New source/File/Folder"
View attachment 116494

Select Source folder and then the same steps as before.
You should see this:

View attachment 116495

Now select column "Result" and go to menu "Home/Transform/Split Column/By Delimiter", select "Semicolon" and "Each occurence of the delimiter", click ok. You should see this:

View attachment 116505

5. Go to menu "Combine/Merge Queries/Merge Queries as New"
View attachment 116496

Select Data in the first, and Source in the second. Then click the target column in both. Below select "Inner" as the Join Kind:

View attachment 116503

You will get this:

View attachment 116504

Click on the marked icon and uncheck target from the list, and uncheck "Use original column name as prefix" (no neccesary).
Then you can rename and reorder the columns as needed.

6. Last remove the target column (right click, remove). And click menu Close&Load. You will get 3 new sheets, Data, Source and Merge1. You can delete sheets Data and Source if you like. In Merge1 you should get the result:

View attachment 116506


Let me know if this works for you or if you need any assistance.
Thanks a lot for your solution .
The first file that contain target ,type , result columns will change by user .
could I let the power query to do the same steps automatic , when the user change the first file in folder ?
If yes ,how ?
I appreciate it ,thanks a lot .
 
Upvote 0
Once the file is changed or you add new files (with more data) to that folder
go to your excel file and go to menu Data and "Refresh All". Result should update with the new data.
 
Upvote 0
Once the file is changed or you add new files (with more data) to that folder
go to your excel file and go to menu Data and "Refresh All". Result should update with the new data.
thanks a lot .
I will try your method .
Could I understand something from your experience ,
When do u decide to use macro script ?
When do you decide to use power query ?
 
Upvote 0

Forum statistics

Threads
1,224,801
Messages
6,181,047
Members
453,014
Latest member
Chris258

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