Combine data from multiple sheets in excel
Question:
Problem description (simplified of course):
I have a list of employees (by ID number) and date (by yr & mon) of when they were assigned a certain duty (task). This is in a Work book, on a TAB. Each TAB is a separate month (first is Jan, 2nd is Feb, etc.). I have 12 tabs (12 worksheets) in workbook. Each TAB, a single month, has a list of ID numbers. Some IDs may repeat on different worksheets, that is, some may be in multiple months and some may be in just two or three months or just one month. An ID number will shown only once in a month for a single task (duty). Abbreviated example is below.
Is it possible to combine the data, by function, or formula, or VBasic) to a 13th worksheet automatically and:
1. Show a list of all ID numbers in order (without repeating).
2. Show Jan data in col B, Feb data in col C, etc., and some columns will be blank because the ID had no assignment that month, and will not be on the worksheet for that month.
Is there a formula, or function, or does it have to be done in VBasic? (Is it even possible?)
I have the workbook with 12 tabs in it, and now have to manually put the ID columns side by side and copy and slide down one side on the other to get them to match, and repeat the process 12 times to get the yearly data on one worksheet.
Ex:
For Jan:
ID Duty Asgn.
01 C
05 F
09 D
15 X
23 P
For Feb:
ID Duty Asgn.
02 M
05 Q
08 A
12 R
20 W
Combing Jan and Feb would be:
ID Duty Asgn.
01 C
02 M
05 F Q
08 A
09 D
12 R
15 X
20 W
23 P
This would be repeated for each month to build all 12 col months.
Very Respectfully,
Dave Bonar
Answer:
First I thought your question required vba but here is the answer using only Excel formulas.
Maximum ID number from multiple sheets
Formula in cell B1:
Create a sorted unique distinct list of numbers originating from multiple sheets
We are going to use the number calculated in B1 (28) in array formula in cell A4 (bolded):
copied down as far as needed.
Combine data from multiple sheets
Formula in B4:
copied down as far as needed.
Formula in C4:
copied down as far as needed.
Formula in D4:
copied down as far as needed.
Download excel tutorial file
Get-data-from-each-sheet.xls
(Excel 97-2003 Workbook *.xls)
Functions in this article:
IF(logical_test;[value_if:true];[value_if_false])
Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE
INDEX(array,row_num,[column_num])
Returns a value or reference of the cell at the intersection of a particular row and column, in a given range
ROW(reference) Returns the rownumber of a reference
SMALL(array,k) Returns the k-th smallest row number in this data set.
MAX(number1,[number2],)
Returns the largest value in a set of values. Ignores logical values and text.
FREQUENCY(data_array, bins_array)
Calculates how often values occur within a range of values and then returns a vertical array of numbers having one more element than Bins_array.
MATCH(lookup_value;lookup_array; [match_type]
Returns the relative position of an item in an array that matches a specified value
ISERROR(value)
Checks whether a value is an error and returns TRUE or FALSE
Merge Ranges Add-In for Excel 2007/2010
Merge Ranges add-in is an user defined function for Excel 2007/2010 (32 bit OS) that let´s you merge multiple ranges into one master sheet in Microsoft® Excel.
Features
- Master sheet is instantly updated when values in a range are edited/added or deleted.
- Possible to merge up to 255 different ranges (Excel 2007).
- Easy to use custom function.
- Get all data from all ranges.
- Column headers in master sheet selects what column data to merge.
- Blank records are not added to master sheet.
- BONUS: Fetch unique distinct records or values from all ranges.
- BONUS: Filter duplicate records or values from all ranges.
Examples
Example 1 - Get all data from all ranges (Click to expand)In this example there are four sheets. Master sheet and three sheets to be merged.
Sheet2
Sheet 2,3 and 4 contains data about people (Fake randomly generated data). The ranges also have some blank records. Click to expand.
Master sheet
Master sheet contains all data from all three ranges merged into one list. Nothing is removed except blank records. Column headers in master sheet rearranges columns automatically. Compare above picture with picture below and see how the order of column headers can be changed in any way you like.
How to use custom function in excel 2007
The user defined function:
=MergeRanges([filter_type], lookup_header(s), range1, range2, ...)
filter_type
0 - Get all records from all ranges
1 - Get unique distinct records from all ranges
2 - Filter all duplicate records from all ranges
lookup_header(s) is a cell reference to a range of values (column headers)
range1, range2, ... are cell references to cell ranges to merge. Each cell range have column headers in first row. There can be as many as 255 cell references.
Example 2 - Filter unique distinct records from all ranges (Click to expand)
In this example there are four sheets. Master sheet and three sheets to be merged.
Sheet2
Sheet 2,3 and 4 contains data about people (Fake randomly generated data). The ranges also have some blank records. Click to expand.
Master Sheet
Master sheet contains unique distinct records from all three ranges merged into one list. Nothing is removed except blank records. Column headers in master sheet rearranges columns automatically. Compare above picture with picture below and see how the order of column headers can be changed in any way you like.
How to create unique distinct records using custom function
The user defined function:
=MergeRanges([filter_type], lookup_header(s), range1, range2, ...)
filter_type
0 - Get all records from all ranges
1 - Get unique distinct records from all ranges
2 - Filter all duplicate records from all ranges
lookup_header(s) is a cell reference to a range of values (column headers)
range1, range2, ... are cell references to cell ranges to merge. Each cell range have column headers in first row. There can be as many as 255 cell references.
Example 3 - Filter duplicate records from all ranges (Click to expand)
In this example there are four sheets. Master sheet and three sheets to be merged.
Sheet2
Sheet 2,3 and 4 contains data about people. (Fake randomly generated data). The ranges have column headers in first row (requirement). There are also some blank records.
Master sheet
The Merge Ranges Add-in found one duplicate record from all three ranges combined.
What you get
- Merge Ranges Add-in for Excel 2007 *.xlam file.
- Instructions on how to install.
- Instructions on how to use custom function.
- Excel 2007 *.xlsm example file.
- 2 licenses, home and office computer.
- You can buy VBA source file for $10 more.
Purchase Merge Ranges Add-In for Excel 2007 - Price $19 US
Purchase Merge Ranges Add-In for Excel 2007 (unlocked, you can view and edit vba code) - Price $29 US
Questions:
Do column headers in master sheet need to be arranged in the same way as column headers in other sheets/ranges?
No, you can rearrange column headers as you like. A requirement is that they have identical spelling (not case sensitive).
Do I need to have as many column headers in master sheet as in the other ranges?
No, you can have fewer column headers in your master sheet, if you like.
How do I enter this user defined function? It is an array formula.
- Type user defined function in formula bar.
- Press and hold Ctrl + Shift.
- Press Enter once.
- Release all keys.
Is there a money back guarantee?
Sure, you have un-conditional money back guarantee for 14 days.
Can I view the vba source code?
No, it is locked for viewing but you can buy VBA source file for $10 more.
Why only excel 2007?
I have not been able to test the add-in in other excel versions.
I have more questions?
Use this contact form to let me know.
Purchase Merge Ranges Add-In for Excel 2007 - Price $19 US
Purchase Merge Ranges Add-In for Excel 2007 (unlocked, you can view and edit vba code) - Price $29 US
How the Purchase Process Works?
- Payment is accepted via PayPal.
- After you finish payment, you are redirected to the download page. You will also receive an email with the download link.
- You have five attempts to download the file.
- The download link will expire in 120 hours (5 days).
If you can´t downloading the file, contact me.
Related posts:
Split data across multiple sheets in excel (vba)
Return unique and duplicate numerical data entries from multiple sheets (3D range) in excel
Consolidate sheets in excel (vba)
Search for multiple text strings in multiple cells and use in data validation in excel





























It looks like you are assuming that everyone knows that this technique can return the # of unique data entries from a real 3D range.
=SUM(IF(FREQUENCY(Jan:Mar!$K$1:$L$3,Jan:Mar!$K$1:$L$3)>0,1))
I am pretty sure that no one has ever done this before, so congratulations!
David Hager,
Thanks!!
/Oscar
Hi Oscar,
I am not sure if my problem is something which is similar to what you have done here or not. I hope that you would know and could help me so I will give it a try....
I have multiple worksheets in a workbook. Each worksheets is project specific. Each worksheet contains almost identical format. The columns I am interested in each workshets are "Date Plan", "Date Compelted" and "variance" and "Project Code"
I then want data from all these column to be extracted in a Report worksheet and later want to do a trend chart by sorting all dates in chronological order.
Key bit to start is how do I get data out from worksheets. Esentially I want all the data without any loss. There are chances that some of the data between worksheet1 & 2 could be identical, apart from project code.
Also, preference is that this coding or formula should work for any future addition to worksheet data and workbook worksheets.
I am not sure if I manage to explain everything very clearly. Please do not hesitate to email me if you need more clarification.
Best Regards,
Jignesh
Hi Jignesh!
Interesting question!
I´ll post an answer as soon as I can.
Thanks Oscar,
Really appreciate your input and help. I am wondering if there would be a way to write a formula with lookup function to get the date from various worksheet...
say if I ask to search for January data then I am expecting January data from all work sheet to be extracted and copied in my Report worksheet.
I can then have 12 X 4 ( For Key Columns - date plan / completed / variance and project code) different columns with all monthly data from various worksheet.
I would then need to plot a chart using the variance data....
Problem is I am not sure if this is possible and if yes, how to write such fomula
Hello, Oscar,
First of all id like to thank you for your blog. I have found many very usefull tips and answers, but still i have one problem that i cant solve by my self. So im asking for your help.
Here is the problem:
i have a data table with 2 columns:
A B
2.93 12.8
2.94 12.2
3 8.38
3.03 6.76
3.04 5.33
3.06 6.36
Lets say i have a cell with number 3. I need to find a number in column A that has a number >= than 3, but also has the smallest number in column B.
(with my cell = 3 it would be 3.04 from A and 5.33 from B)
Simple vlookup gives me first >= number, but in most cases in column B is not the smalest number.
I hope you can help me,
Best regards,
Liudas
Liudas,
See this post: http://www.get-digital-help.com/2010/03/24/lookup-using-two-criteria-in-excel/
Jignesh,
I think I can solve your problem using vba. I hope I can post a solution here soon.
Jignesh,
see this post: http://www.get-digital-help.com/2010/03/29/consolidate-sheets-in-excel-vba/
Thanks a lot Oscar! You are genius! Thanks again!
hi..i have been working on my problem for quite sometime now...i wud b very thankful if u cud provide me the solution.
problem: i have created a workbook containing 12 sheets each corresponding to a month. each sheet has 3 fields-region,premium, claims and ICR. Mow i want to consolidate this data using drop down menus such that wen i select say january month from the drop down, january months data for all the regions shoud be dsiplayed ans similarly for all other months. in addition region should also be in a drop down i.e. wen viewing the data for a particular month, i could select a region and then view its data.
Pls help me in this
Hello,
Is is possible to get this work with ID-names not numbers?
Here: "Create a sorted unique distinct list of numbers originating from multiple sheets"
Lets say if i have the id's like ALFA, BETA, GAMMA, DELTA etc. is it possible to collect all these unique names and combine some data from their rows and sheets? I assume the function small doesn't work anymore?
Thanks for good work!
Tjena Jan-Erik!
As far as I know using formulas, no!
But maybe pivot tables can solve your problem?
Excel Pivot Table Tutorial -- Multiple Consolidation Ranges
Hi,
Same logic i need to be use , but there is the problem when my id nos are more then the No.of row values i.e in excel 2007 total no of row is 1048575 , but hear my id value is more then rowno value i.e 5505982 so that i am not able to get the output .
can you plz sugest ..
Thanks
R Thamu
Thamu,
Interesting question!
I never thought row function created numerical limits. 1 to 1048575.
I´ll comment here as soon as I have an answer.
Hi Oscar,
I have a question about merging two excel worksheets into one masterfile.
I have a first worksheet with daily stock price data for hundreds of firms over a couple of years (panel data). I have the following columns: Firm Number, Date and stock price.
Now I have a second worksheet containing accounting data for the same firms over the same years. Since the accounting data is yearly data, this sheet has less observations.
The columns I have in this sheet are: Firm number, Date,Fiscal Year, FiscalYear end month and a few accounting variables.
Now, I want to add in the columns next to the daily stock market data the accounting variables for that specific fiscalyear.
So for example:
I have a row with stock price of firm #1 at 27-12-2010. The accounting worksheet shows that the fiscal-year of firm #1 ends on 31-09-2010, so first I have in someway to determine in the daily stock price file that 31-12-2010 is fiscalyear 2011 for firm #1 and consequently, in the columns next to the stock price per 27-12-2010 I want to add the accounting variables of firm #1 in fiscal-year 2011.
I would like to do this with normal excel formula's (not vba), but I cannot find the solution...
I really hope you can help me!
Thanks in advance!
S.W.
Hi Oscar, i hope you can help.
i have a workbook consisting of several sheets. each sheet depicts data for several critera related to that specific sheet (the row fields are the same across each sheet) which is further broken down into categories specific for that area. in the summary sheet which also share the same rows i should be able to select a category (from a dropdown) which will give me a summary of those fields in each category.
i.e
the headings for the categories on each sheet would be 1 to 100(area 1, area 2, etc). furthermore fields making up the rows for those headings(e.g apples, pears, oranges, etc)
areas might overlap in town sheets.
the sheets are named by town (town 1, town 2, etc)
the summary sheet - i wish to see how many apples, pears, oranges was sold in a specific area across all the towns.
if i select say 'area 2' in the area dropdown, it will search across the sheets and display the totals of each of the items sold for area 2.
thank you for your help...
I need to consolidate some excel workbook into one to make a master list.and i also want to have duplicate to identify on that master sheet,you think you can help me?