C# - MS Excel - Effectively Normalize Data in Spreadsheet

Posted on 2013-01-21
Last Modified: 2013-02-04
I need to normalize data in spreadsheet.  The spread sheet contains 2 worksheets.

Worksheet1 - Contains persons First Name and Last Name - plus other identifying info.
Worksheet2 - Contains persons First Name and Last Name plus Spouse Name, Relationship, and Vehicles

The issue is Worksheet 2.  The worksheet would be easier to work if it was in the below format.

John Doe    Jane Doe    2010 Camaro SS
John Doe    Jane Doe    2013 Acura TL
John Doe    Jane Doe    2005 Ford Explorer

But the spreadsheet provided is using merged cells in Worksheet2 so the data looks like below

John Doe    Jane Doe   2010 Camaro SS
                                      2013 Acura TL
                                      2005 Ford Explorer

I need to combine worksheet1 and worksheet2 into a text file linking them by name (John Doe - as his name would be on the first sheet).

What is the best way to do this?  XML?  List?  etc...  

Please provide code snippet if possible.
Question by:CipherIS
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 11

Expert Comment

ID: 38802592
If it was me working on this, I would create two helper columns in spreadsheet two.

in it I would put formula's that column something like =if(trim(a2)="",D1,A2).  And then key off of the helper column.  

I know you are working in C#, but you can still either build that into your code or update the spreadsheet with the two new columns before normalizing.  And of course delete them afterwards.

The formula would be in Column D.

Author Comment

ID: 38803114
I need to automate the process which means coding in C# or writing a macro from excel that can be called by C#
LVL 10

Expert Comment

ID: 38804109
I think the macro in the attached worksheet comes pretty close to doing what you want. See the output that it generated in Sheet3.
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.


Author Comment

ID: 38805773
There is no macro attached to the spreadsheet.  

Also, any idea how to call it from C#?
LVL 10

Expert Comment

ID: 38807989
I have no idea what happened to the macro that I wrote for this solution. I cannot find it anywhere on my computer. Hopefully I can recreate it without a lot of effort.
LVL 10

Assisted Solution

tdlewis earned 500 total points
ID: 38808100
Try this version.
LVL 10

Accepted Solution

tdlewis earned 500 total points
ID: 38811132
For instructions on calling your VBA macro from C#, see this article:

Author Closing Comment

ID: 38852733

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question