How To List and add days of Month in a set period using VBA in Excel?
Tags: tolistandadddaysofmo, vbamacros
Published: 2021-10-04 02:18:53

---
title: How To List and add days of Month in a set period using VBA in Excel?
published: true
date: 2021-10-01 10:29:40 UTC
tags: ToListAndAddDaysOfMo,VBAMacros
canonical_url: https://geekexcel.com/how-to-list-and-add-days-of-month-in-a-set-period-using-vba-in-excel/
---

In this blog post, you will learn how to  **list and add days of the month in a set period using VBA** in Excel. Let’s see them below!! Get the 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 **start date and end date**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Sample-data-6.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 DaysInPeriod()
Dim StartDate, EndDate As Date
Dim intRow As Integer, intDays As Integer
'Clearing previous content
Range("F10:G1048576").ClearContents
'Getting start and end date
StartDate = Range("G6")
EndDate = Range("G7")
'Initializing the variable to starting row number
intRow = 10
'Listing the months and number of days from starting date to end date
Do    
    intDays = intDays + 1    
    'Checking for last date of the month or when StartDate is equal to EndDate
    If (Month(StartDate) <> Month(StartDate + 1)) Or StartDate = EndDate Then
        'Inserting the month name
        Cells(intRow, 6) = Format(StartDate, "mmmm")
        'Inserting number of days in the month
        Cells(intRow, 7) = intDays
        'Moving to next row
        intRow = intRow + 1
        intDays = 0
    End If    
    'Moving to next date
    StartDate = StartDate + 1
Loop Until StartDate > EndDate
'Getting the sum in the last row
Cells(intRow, 6) = "Total Days"
Cells(intRow, 7) = Application.Sum(Range("G10:G" & intRow))    
End Sub

```

- 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-4-1024x746.png)<figcaption>Save the Code</figcaption>

- 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-5.png)<figcaption>Run the Code</figcaption>

- Finally, you will receive **output as list and add days of the month in a set period** using VBA as given below.

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

## Summary

We hope that this tutorial gives you guidelines on how to  **list and add days of the month in a set period using VBA** in 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/) **!!**

**Related Articles:**

- **[Excel Formulas to Calculate the Interest for Given Period ~ Quickly!!](https://geekexcel.com/excel-formulas-to-calculate-the-interest-for-given-period/)**
- **[Excel Formulas to Find the Number of Days in a Month ~ Simple Method!!](https://geekexcel.com/excel-formulas-to-find-the-number-of-days-in-a-month-simple-method/)**
- **[Formulas to Calculate the Average of Numbers!!](https://geekexcel.com/excel-formulas-to-calculate-the-average-of-numbers/)**
- **[Excel Formulas to Get the Largest Value with Criteria!!](https://geekexcel.com/excel-formulas-to-get-the-largest-value-with-criteria/)**
- **[Excel Formulas to Calculate the Principal for Given Period ~ Easily!!](https://geekexcel.com/excel-formulas-to-calculate-the-principal-for-given-period/)**