Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with merging excel files based on identical IDs

Hi,

How do you create  one excel file from two excel files based on identical IDs?

For example if Fle1 contains:

ID   NSN      NAS                  AGD
0     Name   Location          Address
1    NameA  LocationA         AddressA

and File2.xls contains

ID   NSC      FIF                     NASC
0     XXXX     YYY                   ZZZZZ
1     AAAA     BBB                 CCCCC

How do I create File3 by merging File1 with File2?

File3.xls

ID   NSN      NAS                  AGD                     NSC        FIF    NASC
0     Name   Location          Address               XXXX     YYY    ZZZZZ
1    NameA  LocationA         AddressA           AAAA     BBB   CCCCC

Thanks,

Victor
Avatar of kulboy
kulboy

Can you give some more info, on what the goal is?  Do you want do do it from a ,net program?  can you do it with excell itself?  Is the amount of columns fixed??
Avatar of Mlanda T
Excel VLOOKUP
You can do this with the VLOOKUP command. I would perhaps put the two worksheets into the same file, seperate sheets. I have attached a sample showing how the VLOOKUP formula would accomplish this.

RDBMS Solution
However, that said, that, the VLOOKUP is really not the best for this sort of thing. You are trying to do a JOIN between two worksheets. This is a classic problem that has already been solved a million times over with relational database systems such as Access database or SQL Server. i would much sooner go the Access route. Import the sheets into Access and jsut create a view that joins the data on the ID column.
VLookupSample.xlsx
Avatar of Victor  Charles

ASKER

Hi,

I would like to achieve it using VB.NET (Windows App).

Victor
In .NET code, I would use a library like  Epplus (http://epplus.codeplex.com)   to read the files into a dataset, then do a job operation add shown by Microsoft here HOW TO: Implement a DataSet JOIN helper class in Visual C# .NET https://support.microsoft.com/en-us/kb/326080
Hi,

Thanks for the link (codeproject)  but it's not for what I am trying to achieve, I need to merge the data in the same worksheet.

Thanks also for the other links but would prefer to avoid third party controls if at all possible.

Victor
Technically, you don't have to use Epplus. I just tend to use it to make loading data from Excel easier. But you could still load the data from Excel into a datatable with ADO.NET OleDb. http://www.codeproject.com/Tips/705470/Read-and-Write-Excel-Documents-Using-OLEDB

One you have the datatables in memory, then do the join between them as Microsoft has shown
Hi

Do you have a link for sollution in VB.NET?

Thanks,

V.
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank You.