Sort dates within a date range using excel array formula
Question: I have a list of unsorted dates. I want to extract records between two dates and I want the extracted dates sorted? A picture of the unsorted dates to the right.
Answer: See picture below.
Formula in D5:D15:
=INDEX(List, MATCH(SMALL(IF((List>=start_date)*(List<=end_date), MATCH(List+ROW(List)/1048576, SMALL(List+ROW(List)/1048576, ROW(List)-ROW(List_start)+1)), ""), ROW()-ROW(sorted_list_start)+1), MATCH(List+ROW(List)/1048576, SMALL(List+ROW(List)/1048576, ROW(List)-ROW(List_start)+1)), 0)) + CTRL + SHIFT + ENTER
Named ranges
List (A1:A10)
List_start (A1)
sorted_list_start (D5)
start_date (E1)
end_date (E2)
How to customize the formula to your excel workbook
Change the named ranges
Download excel example file
sort-dates-within-a-date-range-using-excel-array-formula.xls
(Excel 97-2003 Workbook *.xls)
Functions used in this blog post:
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
SMALL(array,k) returns the k-th smallest row number in this data set.
ROW(reference) returns the rownumber of a reference
MATCH(lookup_value;lookup_array; [match_type])
Returns the relative position of an item in an array that matches a specified value







June 15th, 2009 at 8:24 pm
I am trying to create an excel spreadsheet that has a date range. Example: Cell A1 1/4/09-1/10/09
Cell B1 1/11/09-1/17/09
Cell C1 1/18/09-1/24/09
How do I create a formula to do this?
June 16th, 2009 at 8:05 am
See this blog post: http://www.get-digital-help.com/2009/06/16/create-a-date-range-using-excel-formula/