How to Sort Birthdays by Month and Day in Excel (5 Ways)

We have a sample dataset where the birthdays are not arranged orderly.

how to sort birthdays in Excel by month and day


Method 1 – Using the Combination of MONTH and DAY Functions

To sort the birthdays by months and days ignoring years, arrange the dates from January to May and the days within these months will be arranged in ascending order.

how to sort birthdays in Excel by month and day

Steps:
➤ Enter the following formula in cell E4.

=MONTH(D4)

MONTH will give the serial number of the months of the dates in the Birthday column.

MONTH and DAY functions

➤ Press ENTER and drag down the Fill Handle tool.

MONTH and DAY functions

It will output the serial number of months of the corresponding birthdays.

how to sort birthdays in Excel by month and day

To extract the days from the dates of the Birthday column, we will use the following formula

=DAY(D4)

DAY will give the serial number of the days of the dates in the Birthday column.

MONTH and DAY functions

Sort the values of the Month column and the values of the Day column in an ascending order to arrange the birthdays serially by month and then day.
➤ Select the dataset and go to the Home Tab >> Editing Group >> Sort & Filter Dropdown >> Custom Sort Option.

MONTH and DAY functions

➤ Click on the My data has headers option and select the following in the Sort by box,
Column → Month
Sort On → Cell Values
Order → Smallest to Largest

how to sort birthdays in Excel by month and day

Add the Day column to sort the days’ values after sorting the months.
➤ Select the Add Level option to add the second sorting field.

MONTH and DAY functions

➤ Select the following in the Then by box,
Column → Day
Sort On → Cell Values
Order → Smallest to Largest
➤ Press OK.

MONTH and DAY functions

The dataset is sorted based on the birthdays as shown in the image below.

how to sort birthdays in Excel by month and day


Method 2 – Using the TEXT and VALUE Functions to Sort Birthdays by Month and Day

U

Using the TEXT function and VALUE function, we will combine the serial numbers of the month and day of the dates of the Birthday column and for this purpose, we have added the Text and the Value column in the sample dataset.

how to sort birthdays in Excel by month and day

Steps:
➤ Enter the following formula in cell E4.

=TEXT(D4,"mdd")

TEXT will change the format of the date in D4 in mdd format where m means month and d means day.

TEXT and VALUE functions

➤ Press ENTER and drag down the Fill Handle tool.

TEXT and VALUE functions

It will output the combined month and day values in text format in the Text column.

how to sort birthdays in Excel by month and day

Convert the texts into values by using the following formula

=VALUE(E4)

VALUE will convert the text string in E4 into a numeric value.

TEXT and VALUE functions

To sort the values of the given dataset based on the Value column.
➤ Select the dataset and go to the Home Tab >> Editing Group >> Sort & Filter Dropdown >> Custom Sort Option.

TEXT and VALUE functions

➤ Click on the My data has headers option and select the following in the Sort by box,
Column → Value
Sort On → Cell Values
Order → Smallest to Largest
➤ Press OK.

TEXT and VALUE functions

The birthdays will be sorted by month and day.

how to sort birthdays in Excel by month and day

Read More: How to Sort by Month in Excel


Method 3 – Arranging Birthdays by Using the DATE Function

Steps:
➤ Enter the following formula in cell E4.

=DATE(2020,MONTH(D4),DAY(D4))

2020 is a random year by using this year we will have the same year for all of the dates in the Date column and so we will be able to ignore the year while sorting.
MONTH will extract the month value of the date in D4 and DAY will give the day of the date in D4.

DATE Function

➤ Press ENTER and drag down the Fill Handle tool.

DATE Function

The year will be the same for all, but with the corresponding months and days of the dates of the Birthday column.

how to sort birthdays in Excel by month and day

To sort the values of the following dataset based on the Helper column,
➤ Select the dataset and go to the Home Tab >> Editing Group >> Sort & Filter Dropdown >> Custom Sort Option.

DATE Function

➤ Click on the My data has headers option and select the following in the Sort by box,
Column → Helper
Sort On → Cell Values
Order → Oldest to Newest
➤ Press OK.

DATE Function

The dataset is sorted based on the birthdays as shown in the image below.

how to sort birthdays in Excel by month and day

Read More: How to Sort Dates in Chronological Order in Excel


Method 4 – Sort Birthdays by Month and Day Using the SORTBY and TEXT Functions

Steps:
➤ Enter the following formula in cell E4.

=SORTBY(B4:C13,TEXT(C4:C13,"mdd"))

B4:C13 is the range on which we want to apply the sorting and TEXT(C4:C13,”mdd”) is the range of the combination of the month and day from the range C4:C13 based on which we will do our sorting procedure.

SORTBY and TEXT Functions

Press ENTER to get the results.

SORTBY and TEXT Functions

The SORTBY function is only available for the Microsoft Excel 365 version.

Read More: How to Sort Dates in Excel by Month and Year


Method 5 – Using VBA Code

Steps:
➤ Go to the Developer Tab >> Visual Basic Option.

VBA Code

Visual Basic Editor will open up.
➤ Go to the Insert Tab >> Module Option.

how to sort birthdays in Excel by month and day

A Module will be created.

VBA Code

➤ Enter the following code

Sub sorting_bdays_by_m_d()
Dim initial_month, initial_day, new_month, new_day As Integer
Dim initial_date As Date, initial_employee As String
Dim initial_ID As Long
For k = 4 To 13
For l = k + 1 To 13
initial_month = Month(Cells(k, 4).Value)
initial_day = Day(Cells(k, 4).Value)
new_month = Month(Cells(l, 4).Value)
new_day = Day(Cells(l, 4).Value)
If (new_month < initial_month) Or (new_month = initial_month _
And new_day < initial_day) Then
initial_date = Cells(k, 4).Value
Cells(k, 4).Value = Cells(l, 4).Value
Cells(l, 4).Value = initial_date
initial_employee = Cells(k, 3).Value
Cells(k, 3).Value = Cells(l, 3).Value
Cells(l, 3).Value = initial_employee
initial_ID = Cells(k, 2).Value
Cells(k, 2).Value = Cells(l, 2).Value
Cells(l, 2).Value = initial_ID
End If
Next l
Next k
End Sub

We have declared initial_month, initial_day, new_month, new_day as Integer, initial_date as Date, initial_employee as String, and initial_ID as Long.
We used two For Next loops one is for k= 4 to 13 (start and end row number of the dataset) and another is for l = k+ 1 to 13 to check the next values of k.
initial_month, initial_day will store the month and day value of a cell within the limit of k and new_month, new_day will store the month and day value of the corresponding next cell for limit l.
IF statement will check if the new_month is less than initial_month or if they are equal then new_day should be less than initial_day and if the condition is fulfilled, the new dates and their corresponding employee id and name of the following cell will take place to the previous cells.

VBA Code

➤ Press F5.
The data will be sorted based on the birthdays by month and day.

how to sort birthdays in Excel by month and day

Read More: How to Sort by Date in Excel


Download Practice Workbook


Related Articles


<< Go Back to Sort by Date in Excel | Sort in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Tanjima Hossain
Tanjima Hossain

TANJIMA HOSSAIN is a marine engineer who enjoys working with Excel and VBA programming. For her, programming is a handy, time-saving tool for managing data, files, and online tasks. She's skilled in Rhino3D, Maxsurf C++, MS Office, AutoCAD, and Excel & VBA, going beyond the basics. She holds a B.Sc. in Naval Architecture & Marine Engineering from BUET and is now a content developer. In this role, she creates tech-focused content centred around Excel and VBA. Apart from... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo