## Sort dates within a date range

**Array formula in D5:**

**How to create an array formula**

- Copy array formula
- Select cell D5
- Paste formula in formula bar
- Press and hold Ctrl + Shift
- Press Enter

**How to copy array formula**

- Select cell D5
- Copy (Ctrl + c)
- Select cell range D6:D15
- Paste (Ctrl + v)

### Explaining formula in cell D5

#### Step 1 - Comparison end date

The less than sign and the equal sig allows you to check if values in cell range are less than or equal to the end date.

($B$3:$B$12<=$E$3)

becomes

{39836;39848;39850;39836;39844;39824;39845;39826;39851;39859}<=39859

and returns

{TRUE; TRUE;TRUE; TRUE;TRUE; TRUE;TRUE; TRUE;TRUE; TRUE}.

#### Step 2 -Â Comparison start date

The greater than sign and the equal sig allows you to check if values in cell range are greater than or equal to the start date.

($B$3:$B$12>=$E$2)

becomes

{39836;39848;39850;39836;39844;39824;39845;39826;39851;39859}>=39828

and returns

{TRUE;TRUE; TRUE; TRUE;TRUE;FALSE;TRUE; FALSE;TRUE; TRUE}

#### Step 3 - Multiply arrays

Both conditions must evaluate to TRUE.

($B$3:$B$12<=$E$3)*($B$3:$B$12>=$E$2)

becomes

{TRUE; TRUE;TRUE; TRUE;TRUE; TRUE;TRUE; TRUE;TRUE; TRUE}*{TRUE;TRUE; TRUE; TRUE;TRUE;FALSE;TRUE; FALSE;TRUE; TRUE}

and returns

{1;1;1;1;1;0;1;0;1;1}

Boolean |
Boolean |
Multiply |

FALSE | FALSE | 0 |

TRUE | FALSE | 0 |

TRUE | TRUE | 1 |

#### Step 4 - Replace TRUE with the corresponding date

The IF function replaces TRUE values with the corresponding dates and FALSE with "A".

IF(($B$3:$B$12<=$E$3)*($B$3:$B$12>=$E$2), $B$3:$B$12, "A")

becomes

IF({1;1;1;1;1;0;1;0;1;1}, {39836;39848;39850;39836;39844;39824;39845;39826;39851;39859}, "A")

and returns

{39836; 39848; 39850; 39836; 39844; "A"; 39845; "A"; 39851; 39859}

#### Step 5 - Sort numbers (dates)

The SMALL function extracts the k-th smallest number and ignores text values like "A".

SMALL(IF(($B$3:$B$12<=$E$3)*($B$3:$B$12>=$E$2), $B$3:$B$12, "A"), ROWS($A$1:A1))

becomes

SMALL({39836; 39848; 39850; 39836; 39844; "A"; 39845; "A"; 39851; 39859}, ROWS($A$1:A1))

The ROWS function counts rows in a cell reference, this cell reference $A$1:A1 expands as the formula is copied to cells below. This will extract a new value in each cell.

SMALL({39836; 39848; 39850; 39836; 39844; "A"; 39845; "A"; 39851; 39859}, ROWS($A$1:A1))

becomes

SMALL({39836; 39848; 39850; 39836; 39844; "A"; 39845; "A"; 39851; 39859}, 1)

and returns "1/23/2009" in cell D6.

### Download Excel *.xlsx file

sort-dates-within-a-date-range-using-excel-array-formula.xlsx

Table of Contents Sort a column using array formula Two columns sorting by the second column Sort alphanumeric values I […]

Create a unique distinct sorted list containing both numbers text removing blanks

The image above demonstrates a formula in cell D3 that extracts unique distinct numbers and text values sorted from A […]

The image above shows a table with two columns in cell range B3:C16, it contains random text values in column […]

Sort column based on frequency

Question: How do I create a new unique distinct list from a column. I alsoÂ want the list sorted from large […]

Sort text cells alphabetically from two columns

Table of Contents Sort text from two columns combined (array formula) Sort text from multiple cell ranges combined (user defined […]

Lookup and return multiple values sorted in a custom order

Pat asks: Hi Oscar, Thanks for creating such a helpful website and I've a question if I would like to […]

Sort values in an Excel table [VBA]

awall asks: Hey, can you do the opposite of this - not random order but this is my situation. I […]

Denisa asks: I have a problem and i cant figure it out, even if i'm seraching for 2 days. I […]

Sort values in a cell using a custom delimiter [VBA]

The following macro lets you select a cell range and a delimiting character. The macro sorts the values in each […]

### 23 Responses to “Sort dates within a date range”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

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?

See this blog post: https://www.get-digital-help.com/2009/06/16/create-a-date-range-using-excel-formula/

I have a very similar problem with dates but my dates are in a matrix (an array). So columns A through J (A2:J60) have dates and I want to put the entire range of dates into one column say column A in sheet 2 but I want them in ascending order. Any chance you can help with that.

Kind Thanks,

Eddie

Eddie G,

Array formula in cell A1, sheet2:

=SMALL(Sheet1!$A$2:$J$60, ROW(A1))

Thanks for bringing this post to my attention. I have now simplified the formula in this post.

I'm using a formula to get a report that bring me the total persons from a specific colum in a determinated date:

{SUM(IF((DATE>=FirstDate)*(DATE<=LastDate)*(TYPE=TypeName)*(SUBTYPE=SubtypeName),NameColum2,0))}

When I want to get the result from the "Name Colum2" it works well, but when I change the colum ("NameColum3") it appears an #NAME? error.

I have an excel spreadsheet that has different colums:

TYPE,SUBTYPE,DATE,NameColum2,NameColum3,etc.

Could you help me?

Thanks

Ed

Ed,

You have probably misspelled the column name.

https://www.exceldigest.com/myblog/2009/03/02/how-to-correct-or-clear-a-name-error-in-a-formula/

Thank you very much! Now it is working very well.

Hi I am trying to apply this formula to a search I need to run. I have 4 types of searches, in a dropdown box with conditional formatting showing the user where to enter the specific data that needs to be searched for. I have been able to complete two the search if statements (bill number and file number) however I can not complete the other two which is invoice number and date range.

I would like the formula to always return the applicable bill num if the start and end date of the invoice falls in the specified range .

the formula is getting so long that I am lost. here is the link ...

https://www.dropbox.com/s/5o3n2kln2u8v7yn/invoice%20for%20lily%20%28Autosaved%29.xlsx

many thanks in advance ...

Juliana,

Download *.xlsx file

invoice-for-lily.xlsx

Hi Pro, i want to find day if given date and week, for example : if given Tuesday, 32th week, 2015 >>> how to use function to point out 4/8/2015 ?

Pls help me!

La ThÄƒng,

Read this:

https://www.get-digital-help.com/2015/08/06/find-date-given-day-and-week/

[…] La ThÄƒng asks: […]

Thanks so much Pro :) if you have chance to VietNam visit, pls tell me know ^^

If I want to search a certain criteria in two dates in above example. For an example, machine A within two dates.How I do it?

Pls help

i have A1 to A300 employee names

B1 to B300 start date of vacation

C1 to C300 end date of vacation

need to count how many employees are absent from work for each day in a year to create a chart (ex: 05.05.2016. 55 are absent, 06.05.2016. 59 are absent... and so on)

and, if its possible to make list of their names... but that is a separate question.

Hi Oscar

Really love your website. Its very useful. I'm using this formula but need help. I have a table with Dates, Codes, Description etc. These table is used to input data which may or may not be in date order.

I then need to copy this data into another area but I want it sorted by date order, which I have successfully done. However, I also want the Codes, Description etc linked to the date to also come across to the sorted date formula used above.

Is this possible?

Hi,

What I have to take on the place of list in this formula??

Pls Help

I am getting Num! Error in this Date Sorting Formula

Did you enter it as an array formula?

I have used in this way

=SMALL(IF((K5:K24=$L$1),K5:K24,""),K5:K24)

Lokesh

You need to use absolute cell refs except the last one, like this:

=SMALL(IF(($A$1:$A$10< =$E$2)*($A$1:$A$10>=$E$1), List, ""), ROW(A1))

Row(A1) returns a number that changes when you copy/paste the formula to cells below. That way you can get the smallest value and then the second smallest value and so on.

Hello Sir,

I have Got the Answer but I didn't understand the presence of Row(A1)in this Formula. Could u pls help me understand that