Solved

C# - MS Excel - Effectively Normalize Data in Spreadsheet

Posted on 2013-01-21
8
345 Views
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.
0
Comment
Question by:CipherIS
  • 4
  • 3
8 Comments
 
LVL 11

Expert Comment

by:ScriptAddict
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.
0
 
LVL 1

Author Comment

by:CipherIS
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#
0
 
LVL 10

Expert Comment

by:tdlewis
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.
Q-28002863.xlsm
0
 
LVL 1

Author Comment

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

Also, any idea how to call it from C#?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 10

Expert Comment

by:tdlewis
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.
0
 
LVL 10

Assisted Solution

by:tdlewis
tdlewis earned 500 total points
ID: 38808100
Try this version.
Q-28002863.xlsm
0
 
LVL 10

Accepted Solution

by:
tdlewis earned 500 total points
ID: 38811132
For instructions on calling your VBA macro from C#, see this article:
http://msdn.microsoft.com/en-us/library/vstudio/bb608613.aspx
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 38852733
Thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now