How To Sort the data by birthday using VBA in Microsoft Excel?
Tags: tosortthedatabybirth, vbamacros
Published: 2021-10-04 02:13:58

---
title: How To Sort the data by birthday using VBA in Microsoft Excel?
published: true
date: 2021-10-01 07:33:53 UTC
tags: ToSortTheDataByBirth,VBAMacros
canonical_url: https://geekexcel.com/how-to-sort-the-data-by-birthday-using-vba-in-microsoft-excel/
---

In this tutorial, we will guide you on how to  **sort the data by birthday using VBA** in Microsoft Excel. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, you need to **create a sample data** with **two columns** , one contains the **name** and second column contains the **birth date**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Sample-data.png)<figcaption>Sample data</figcaption>

- In the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Option Explicit
Sub sorting_names_by_birthday()
'Disabling screen update
Application.ScreenUpdating = False
Dim Last_Row As Long
'Finding the last row
Last_Row = ActiveCell.SpecialCells(xlCellTypeLastCell).Row
Range("C16").Select
'Getting the days of the year
'Subtracting first date of the year from date of birthday
ActiveCell.FormulaR1C1 = "=RC[-1]-DATE(YEAR(RC[-1]),1,1)"
'Dragging the formula
Range("C16:C" & Last_Row).Select
Selection.FillDown
'Sorting the data first by column A then by column C
Range("A15").CurrentRegion.Sort _
      key1:=Range("C15"), order1:=xlAscending, _
      key2:=Range("A15"), order2:=xlAscending, _
      Header:=xlYes      
'Deleting the column C
Columns("C").Delete
Range("A15").Select
End Sub

```

- After that, you need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Save-the-Code.png)

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/10/Run-the-Code-1.png)<figcaption>Run the Code</figcaption>

- Finally, you will receive **output as sorted data by brithday** as given below.

![](https://geekexcel.com/wp-content/uploads/2021/10/Output.png)<figcaption>Output</figcaption>

## Closure

We hope that this tutorial gives you guidelines on how to  **sort the data by birthday using VBA** in Microsoft Excel. Please leave a comment in case of any  **queries,**  and don’t forget to mention your valuable  **suggestions**  as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Further Reference:**

- **[Excel Formulas to Calculate the Age From Birthday ~ Useful Guide!!](https://geekexcel.com/excel-formulas-to-calculate-the-age-from-birthday/)**
- **[How to Sort a Table in Excel Office 365 ~ Complete Tutorial!!](https://geekexcel.com/sort-a-table-excel/)**
- **[Use Excel SORT Function in Office 365 – [with Example]](https://geekexcel.com/excel-sort-function/)**
- **[How to Sort Data by Last Name/Month/Frequency/Text Length in Excel?](https://geekexcel.com/how-to-sort-data-by-last-name-month-frequency-text-length-in-excel/)**
- **[Sort Sheets/Worksheets Alphabetically in Excel Office 365](https://geekexcel.com/how-to-sort-sheets-worksheets-alphabetically-in-excel-office-365/)**