Easy way to normalize Excel worksheets? - excel

I have several fairly good-sized Excel worksheets (indexed by WorksheetID) that essentially amount to flat database tables: rows are the records (indexed by DataRecordID within one worksheet), columns are the fields (indexed by DataFieldID within one worksheet), and the cells contain the field values (Value) for the appropriate records (or are blank).
I'm interested in breaking them apart to (many) records like this so that I can import them into MS Access:
ID | WorksheetID | DataRecordID | DataFieldID | Value
I've already done this manually. I see that it's probably a straightforward matter to write a VBA script to chug through the sheets and (optionally) delete the records in the final table.
My question is: Before I roll up my sleeves and begin coding, is there already a built-in capability in Excel 2010 that I don't even need to write a script to do this?

You don't need a script for this provided the data sources are of consistent layout. The basic process is described (with pictures!) here. However since that was considering a single matrix you will need a few extra steps:
Build in to the DataRecordIDs indication of their worksheet origins. Say with a formula such as =A2&"|WorksheetID" copied down to suit in a column inserted as a (new) ColumnB, for all sheets, assuming your first DataFieldID is in A2.
At Step #4 of the process (Step 2b of 3 in the Wizard) you would need to add the relevant ranges from each sheet individually.
Once you have the results Table you would then need to insert a new ColumnB and apply Text to Columns, Delimited with Other | to ColumnA.

Related

Compare users in different sheets and add user to sheet A if not present in A but present in B

We use an Excel file as a support tracker. Our main sheet (A) has a list of users and their data. For daily support, we run the MYSQL stored procedure to get the data, then paste it into a blank sheet (B) that colors and filters the data.
I am supposed to search the users in sheets A and B, and if a user is present in B but not A (scenario representing adding a user to our system) add the missing user to sheet A.
Based on my past programming knowledge, the steps should be:
count rows in sheets A and B
A has more data further down the sheet that is not raw user data, but it is in the same columns so looking for the first blank cell in A
do a compare on those results
if the results are different, do a vlookup to find the missing entry
insert that entire row from sheet B to sheet A
I assume this can be done with VBA code.
You can write a VBA script to do this, and probably should if this is a regular process.
Alternatively a sorting approach will handle this and many similar problems. It works like this, given two sheets A & B with mixed duplicate and unique entries:
Append B to A
Sort by desired category (User in this case)
This will have duplicates (User) next to each other
Insert a match check column consisting of If User EQ PreviousUser, True, False;
Cut and paste Values to change from a function to simple content of True/False
Sort by True/False column
Delete the entire block of True's
Done!
This approach also works for more than two sheets. Append them all together, sort, mark dups, delete.

Import data into existing table, unique entries

I need to do some aggregation and statistics on data and I'm thinking about doing that with Excel as the raw Data already comes in Excel format. Basically you could say it's kind of a log type of data with Datetime and some more information on each line.
I'm not yet clear what aggregation and other stuff needs to be done on this data but I already know that I need to merge new data into the then existing excel sheet every day or two. There is no real unique identifier in the data but the combination of 2 or more fields could easily be used for uniqueness. I wonder if there's a smart way to import the new data from time to time even if it contains already existing data then. Maybe something like copy it into a new tab/sheet then start some kind of import action where uniqueness gets checked?
I'm unsure if this can be done with Excel at all so please bear with me if the question sounds stupid to excel pro's.
Assume in a worksheet columns A and C can be combined for uniqueness. You could concatenate them to create an id:
In D2 = concatenate (A2,C2)
Then, add another worksheet of data, with this same concatenated column D added.
Then, add a third worksheet with a formula to only show unique data rows:
In worksheet 3 A2: =if(countif(sheet1!d:d,sheet2!d2))>0,"",sheet2!a2
In worksheet 3 B2: =if(countif(sheet1!d:d,sheet2!d2))>0,"",sheet2!b2
In worksheet 3 c2: =if(countif(sheet1!d:d,sheet2!d2))>0,"",sheet2!c2
This will create a sheet of unique ids with some rows (those that are unique) populated. You could copy and paste this as values only, the sort by any of the headings to get at the unique data only.
This is not the most efficient way to do this at all, but it will work in a pinch.

Data consolidation using Columns

We sell our product via a number of different retailers. These shops send us reports of what they have sold and we need to import this into our new stock management system as a master file.
The stores do not and will not provide the data in a uniform way based on our desired template.
I therefore need a way of consolidating ranges of data that without having a unique ID for each line, with minimal manual formatting from the data importer to help save time.
http://s14.postimg.org/arslbnnxt/excelconsolidation.jpg
As you can see in the 2 examples above, nothing is in the same order and some of the supplied fields haven't been used. The column headers are static, only the data is actually pasted.
I've tried using the Excel Data consolidation tool but the SUM function just wants to add everything up or simply reports a single value, I've played with Vlookup but I then need to dedicate a number of rows to each store which results in lots of empty rows.
If you can point me in the right direction I'm more than happy to research the tool or function I need, web searches keep bringing me back to the consolidation tool.
Many thanks,
Since you say that column headers are static, you actually do have a unique ID.
The task can be accomplished by using HLOOKUP with Column headers as lookup value.
However, the formula will depend on how you organize or store input sheets from different stores.
Here I have tested a setup where each store input is pasted in consecutive sheets starting from 'Sheet1'. i.e. Store1 in Sheet1, store2 in Sheet2 ... with row 1 containing header.
Then in consolidated sheet using helper columns for identifying sheet and row number, the formulas look like this
in A2 =IFERROR(HLOOKUP(A$1,INDIRECT("Sheet"&$H2&"!A:O"),$I2,0),"")
in H3 =IFERROR(IF(INDIRECT("Sheet"&H2&"!A"&I2+1)="",H2+1,H2),"") (if no more records, increment sheet number)
in I3 =IFERROR(IF((H3-H2)=0,I2+1,2),"") (if sheet number changed, reset row number to 2)
Initial value for H2 = 1 , I2 = 2
Test file: Storefile

Merge two unique excel spreadsheets, remove one spreadsheet when needed

Hopefully I can explain this decently.
I am attempting to merge two unique excel spreadsheets, with some of the same data, into one spreadsheet. When needed I would like to remove the data from the incoming spreadsheet. I am doing this as it would make it easier to edit one "like" spreadsheet, rather then keep and update two copies. I do not want to hide the incoming data, I NEED to completely remove it when needed.
Thanks!
It depends on what the spreadsheets look like and what, exactly, you mean by merge.
If, for example, the two worksheets contain a table each, then you could copy/append one table to the bottom of the other and use Excel's Remove Duplicates feature (on the Data tab) to delete rows.
The duplicates can be identified either by a single code-number column, all of the columns (meaning that the entire row is duplicated) or a selection of columns. Be aware that it is the first duplicated row that is kept, the subsequent duplicates will be removed.
If, on the other hand, you want to find values in the rows of one of the worksheets, based on a code number contained in a column of the other worksheet, and insert them into specific cells, then this requires more effort, perhaps with the help of the VLOOKUP function (or similar).

Combining Excel sheets/groups of columns by a condition in Excel 2007

Is there a way to combine 2 Excel sheets (or groups of columns inside one Excel sheet) so that the rows in one sheet/group append to the other sheet/group where so that certain columns values match.
To clarify:
Lets say I have 2 sheets - Sheet1 and Sheet2. Sheet1 has the columns A,B,C,D. Sheet2 has columns A,E,F,G. Column A in both sheets contains the same data but differently sorted (it is not sorted in conventional way (alphabetically or numerically)). I need to combine these 2 sheets into one, but they need to be combined so that the values in A column match (if possible the result should be ordered in the same way as the Sheet2).
Ideally, the functionality I'm looking for would need to be like SQL's INNER JOIN command.
I'm using Excel 2007.
Thanks
I think you basically described the VLOOKUP function.
You have your two sheets, now you want to create a list, which extends A,B,C,D to A,B,C,D,E,F,G.
For that, you could just use
Sheet1!E1=VLOOKUP(Sheet1!A1,Sheet2!A:G,5,FALSE)
Sheet1!F1=VLOOKUP(Sheet1!A1,Sheet2!A:G,6,FALSE)
Sheet1!G1=VLOOKUP(Sheet1!A1,Sheet2!A:G,7,FALSE)
If you need to create an extra sheet3 as a result, use this:
Sheet3!A1=Sheet1!A1
Sheet3!B1=VLOOKUP(Sheet3!A1,Sheet1!A:D,2,FALSE)
Sheet3!C1=VLOOKUP(Sheet3!A1,Sheet1!A:D,3,FALSE)
Sheet3!D1=VLOOKUP(Sheet3!A1,Sheet1!A:D,4,FALSE)
Sheet3!E1=VLOOKUP(Sheet3!A1,Sheet2!A:G,5,FALSE)
Sheet3!F1=VLOOKUP(Sheet3!A1,Sheet2!A:G,6,FALSE)
Sheet3!G1=VLOOKUP(Sheet3!A1,Sheet2!A:G,7,FALSE)
Hope this interpretation was correct.
Edit:
By the way, because Excel is not mainly intended to function as a database, this operation is a bit messy, because it does not dynamically scale. At least with the second approach, using a thrid sheet. You will have to copy down A1 at least that far, to match the last used row from Sheet1. And if you should copy it down further, so you won't have to worry about it for a while, you might need to error-proof against the empty cells.

Resources