Merge two columns with possible blank cells in excel (formula)
Question:
This article is terrific. Thanks so much for posting this solution!
I do have one question:
Let's say my "List 1" is auto updated and the number of entries in this list will fluctuate. Since the number of entries fluctuates, I would like to select a larger range than I actually have data in currently. The issue is when I make my "List 1" larger than the number of entries, the rows that don't currently have data in them, show up on my combined list as zeros.
So my question is, is there a way to adjust the formula so that when it looks at "List 1" for example, it skips over blank cells and continues to combine the list with "List 2".
(You can find the question here: Merge two columns into one list in excel)
Answer:
The array formula below removes blank cells. Another method is to use dynamic named ranges.
Array formula in C2:
Copy cell C2 and paste it down as far as needed.
Named ranges
List1 (A2:A7)
List2 (B2:B5)
What is named ranges?
Explaining array formula in cell C8
Step 1 - Understand relative and absolute cell referencing
In cell C2 the formula is:
=IFERROR(INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A1))), IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A1)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), ""))
In cell C8 the formula is:
=IFERROR(INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A7))), IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A7)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), ""))
Step 1 - Find cells containing a value in List 1 and return row numbers in an array
=IFERROR(INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A7))), IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A7)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), ""))
IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1)
becomes
IF(ISBLANK({"AA";"DD";"";"GG";"HH";"TT"}), "", ROW(A2:A7)-MIN(ROW(A2:A7))+1)
becomes
IF({FALSE;FALSE;TRUE;FALSE;FALSE;FALSE}, "", {2;3;4;5;6;7}-MIN({2;3;4;5;6;7})+1)
becomes
IF({FALSE;FALSE;TRUE;FALSE;FALSE;FALSE}, "", {2;3;4;5;6;7}-2+1)
becomes
IF({FALSE;FALSE;TRUE;FALSE;FALSE;FALSE}, "", {1;2;3;4;5;6})
and returns
{1;2;"";4;5;6}
Step 2 - Return the k-th smallest row number
=IFERROR(INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A7))), IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A7)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), ""))
SMALL(array,k) Returns the k-th smallest number in this data set.
SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A7))
becomes
SMALL({1;2;"";4;5;6}, 8 )
and returns #NUM
Step 3 - Return a value of the cell at the intersection of a particular row and column
=IFERROR(INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A7))), IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A7)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), ""))
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
INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A7)))
becomes
INDEX(List1, #NUM)
and returns
#NUM
Step 4 - Check if formula returns an error
=IFERROR(INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A7))), IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A7)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), ""))
becomes
=IFERROR(#NUM, IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A7)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), ""))
becomes
IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A7)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), "")
Step 5 - Find cells containing a value in List 2
IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A7)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), "")
IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1)
becomes
IF(ISBLANK({"MM";"";"WW";"TT"}), "", {2;3;4;5}-MIN({2;3;4;5})+1)
becomes
IF({FALSE;TRUE;FALSE;FALSE}), "", {1;2;3;4})
and returns
{1;"";3;4}
Step 6 - Return the k-th smallest row number
IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A8)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), "")
SMALL(array,k) Returns the k-th smallest number in this data set.
SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A8)-SUMPRODUCT(--NOT((ISBLANK(List1)))))
becomes
SMALL({1;"";3;4}, ROW(A7)-SUMPRODUCT(--NOT((ISBLANK(List1)))))
becomes
SMALL({1;"";3;4}, 7-SUMPRODUCT(--NOT((ISBLANK({"AA";"DD";"";"GG";"HH";"TT"})))))
becomes
SMALL({1;"";3;4}, 7-SUMPRODUCT(--NOT({FALSE;FALSE;TRUE;FALSE;FALSE;FALSE})))
becomes
SMALL({1;"";3;4}, 7-SUMPRODUCT(--{TRUE;TRUE;FALSE;TRUE;TRUE;TRUE}))
becomes
SMALL({1;"";3;4}, 7-SUMPRODUCT({1;1;0;1;1;1})
becomes
SMALL({1;"";3;4}, 7-5)
becomes
SMALL({1;"";3;4}, 2)
and returns 3.
Step 6 - Return a value of the cell at the intersection of a particular row and column
IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A8)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), "")
becomes
IFERROR(INDEX(List2, 3), "")
becomes
IFERROR(INDEX({"MM";0;"WW";"TT"}, 3), "")
becomes
IFERROR("WW", "")
and returns WW.
Download excel sample file for this tutorial.
merge-two-columns with blanks.xlsx
(Excel 2007 Workbook *.xlsx)
Functions in this article:
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
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
ISBLANK(value)
Checks whether a reference is to an empty cell and returns TRUE or FALSE
MIN(number1,[number2])
Returns the smallest number in a set of values. Ignores logical values and text
ROW(reference) returns the rownumber of a reference
IFERROR(value;value_if_error) Returns value_if_error if expression is an error and the value of the expression itself otherwise
SMALL(array,k) Returns the k-th smallest number in this data set.
SUMPRODUCT(array1, array2, )
Returns the sum of the products of the corresponding ranges or arrays
NOT(logical)
Changes FALSE to TRUE, or TRUE to FALSE
Related posts:
Merge two columns into one list in excel
Merge three columns into one list in excel
Identify missing values in two columns using excel formula
Sort text cells alphabetically from two columns using excel array formula
Filter duplicates from two columns combined and sort from A to Z using array formula in excel



















=IFERROR(INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A1))), IFERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A1)-SUMPRODUCT(--NOT((ISBLANK(List1)))))), ""))
please same for office 2003
Prash,
Excel 2003, array formula in C2:
=IF(ISERROR(INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A1)))), IF(ISERROR(INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A1)-SUMPRODUCT(--NOT((ISBLANK(List1))))))), "", INDEX(List2, SMALL(IF(ISBLANK(List2), "", ROW(List2)-MIN(ROW(List2))+1), ROW(A1)-SUMPRODUCT(--NOT((ISBLANK(List1))))))), INDEX(List1, SMALL(IF(ISBLANK(List1), "", ROW(List1)-MIN(ROW(List1))+1), ROW(A1)))) + CTRL + SHIFT + ENTER
Copy cell C2 and paste it down as far as needed.
Could you please tell me what I need to do to add additional Lists? I'm trying to get 3 lists merged into a single list with no blanks for earlier versions of Excel. Thanks
Shawna,
The array formula would be ridiculously large, too large I think.
I was hoping to be able to add additional lists as well with the ability to remove the spaces. It's not to bad if you leave the spaces between the end of one list and the start of the next in.
=IFERROR(INDEX(List1,ROWS(V$2:V2)),IFERROR(INDEX(List2,ROWS(V$2:V2)-ROWS(List1)),IFERROR(INDEX(List3,ROWS(V$2:V2)-ROWS(List1)-ROWS(Lis2)),"")))
Instead I think I will just do a simply =cell in a new worksheet and than simply sort it.
Denis,
Thanks for a reply...if my data are in columns, do I simply change the formula to read "columns"?
Here is my dilemma: I work in a forensic lab and we typically have samples that undergo different procedures, culminating in a final procedure they all undergo. I am trying to compile a Total Sample List (which combines all of the samples from other lists). The data from the 'Total Sample List' will be drawn into MS Word to populate the forms we use according to sample type (that much I've already figured out). I'm a lab geek, not a computer geek UNFORTUNATELY!
Well, honestly I would have to say just give it a try. You could look at it as an experiment
I'm by no means an expert in excel. I spent a couple hours just modifying the above formula from one that was posted on this website prior.
I've been trying to create something close to this for a long time now for budgeting and cashflow of my personal finances.
-Good Luck!
Can this work, with the same dataset specified above, if the lists are defined :
List1 (A2:A10)
List2 (B2:B10)
instead of
List1 (A2:A7)
List2 (B2:B5)
that is, with trailing blank cells in the list. In my particular example, my lists will be filled top down, with any blank cells at the end, and i do know the maximum number of cells i could possibly have, if that helps.
Cause when i try this, i only get details from the first list.
Thanks
Graeme
Hi All,
so all good.
I hope you are able to help me, must admit I don't do a whole lot with excel in my day to day role so my skills are really limited. The above formula functions OK in my workbook and combines two named ranges together into a single list with no 0's
My question is how would I add a third list, fourth list etc. etc to the formula ?
I'm attempting to set up one list that combines data from several other lists.
Thanks very much
Nathan
I have all 13 lists combined now using the below formula, now just struggling to add in the "Remove Balnks" piece, My application only allows imports from xlsx and not xlsm so I cannot do it the easy way (with a vb macro)
also the application will not recognize the file if it's been renamed
Formula
=IFERROR(INDEX(List1,ROWS(V$2:V2)),
IFERROR(INDEX(List2,ROWS(V$2:V2)-ROWS(List1)),
IFERROR(INDEX(List3,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)),
IFERROR(INDEX(List4,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)),
IFERROR(INDEX(List5,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)-ROWS(List4)),
IFERROR(INDEX(List6,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)-ROWS(List4)-ROWS(List5)),
IFERROR(INDEX(List7,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)-ROWS(List4)-ROWS(List5)-ROWS(List6)),
IFERROR(INDEX(List8,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)-ROWS(List4)-ROWS(List5)-ROWS(List6)-ROWS(List7)),
IFERROR(INDEX(List9,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)-ROWS(List4)-ROWS(List5)-ROWS(List6)-ROWS(List7)-ROWS(List8)),
IFERROR(INDEX(List10,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)-ROWS(List4)-ROWS(List5)-ROWS(List6)-ROWS(List7)-ROWS(List8)-ROWS(List9)),
IFERROR(INDEX(List11,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)-ROWS(List4)-ROWS(List5)-ROWS(List6)-ROWS(List7)-ROWS(List8)-ROWS(List9)-ROWS(List10)),
IFERROR(INDEX(List12,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)-ROWS(List4)-ROWS(List5)-ROWS(List6)-ROWS(List7)-ROWS(List8)-ROWS(List9)-ROWS(List10)-ROWS
(List11)),
IFERROR(INDEX(List13,ROWS(V$2:V2)-ROWS(List1)-ROWS(List2)-ROWS(List3)-ROWS(List4)-ROWS(List5)-ROWS(List6)-ROWS(List7)-ROWS(List8)-ROWS(List9)-ROWS(List10)-ROWS
(List11)-ROWS(List12)),""))
Thanks
Nathan
I think I have this sorted now, I have used dynamic named ranges for List1 --> List13, in the refers to formula is:-
=OFFSET(Sheet1!$A$2,0,0,MATCH("*",Sheet1!$A:$A,-1),1)
this formula seems to work OK in as much that it does not include the column heading "Cell A1" but for some reason it is adding one row to the end?
so In my drop down I see:-
Value - sheet 1
Value - sheet 1
0
Value - sheet 2
0
Value - sheet 3
Value - sheet 3
0
looking at the named range I can see it's selecting one row more than there are values - can anyone explain why it's doing this ? I am sure it's a simple fix
Thanks
Nathan
Nathan,
try this named range:
=OFFSET(Sheet1!$A$2,0,0,MATCH("*",Sheet1!$A:$A,-1)-1,1)
Hi Oscar,
Thanks for getting back to me, I got this working using :-
=IFERROR(INDEX(Servers!A:A,AGGREGATE(15,6,(ROW(Servers!A:A)-ROW(Servers!A3)+1)/(Servers!A:A""),ROWS(C$1:C2))),"")
for each of the 13 lists and then used these ranges to make the drop down
Thanks
Nate
Dear Oscar,
I need to have both functions of columns combine (Skip banks + Distinct Values).
Please help.
Regards,
Alaa Abdullnabi,
See this file:
how-to-extract-a-unique-list-from-two-columns-in-excel-2007-no-blanks.xlsx
GREATTTTTT, REALLY MANY MANY THANKS... YOU ARE ONE OF THE BEST.