# Excel VBA: First Day of Month (3 Methods)

While working with Excel, sometimes we need to know the first day of the given date or month. But there is no direct function or formula in Excel to generate the First Day of Month from the Date or the Month Name. We can easily calculate the first day of the month by using the VBA Macros. Today, in this article, we’ll learn four quick and suitable ways how to calculate the first day of the month by using the VBA code in Excel effectively.

## VBA to Count the First Day of Month (Quick View)

``````Sub First_Day_Of_Month()
strDate = DateValue(Range("C5"))
Range("D5") = DateSerial(Year(strDate), Month(strDate) - 1, 1)
Range("D6") = DateSerial(Year(strDate), Month(strDate) + 1, 1)
Range("D7") = DateSerial(Year(strDate), Month(strDate), 1)
End Sub
`````` ## 3 Suitable Ways to Get the First Day of Month Using VBA in Excel

Let’s consider a situation where we have an Excel worksheet that contains information about a sales representative named Emma of the Armani group. Her joining date is given in column C. We will calculate the first day of the corresponding joining date by using the simple VBA code. Here’s an overview of the dataset for today’s task. ### 1. Develop a VBA Code to Count the First Day of Current Month in Excel

From our dataset, we will count the first day of the month of the corresponding date by using a simple VBA code. It’s very helpful for some particular moments. Let’s follow the instructions below to learn!

Step 1:

• First of all, select the continuous data rows that you want to select from your dataset, and then from your Developer tab, go to,

Developer → Visual Basic • After clicking on the Visual Basic ribbon, a window named Microsoft Visual Basic for Applications – First Day will instantly appear in front of you. From that window, we will insert a module for applying our VBA code. To do that, go to,

Insert → Module Step 2:

• Hence, the First Day module pops up. In the First Day module, write down the below VBA
``````Sub First_Day_Of_Month()
strDate = DateValue(Range("C5"))
Range("D5") = DateSerial(Year(strDate), Month(strDate), 1)
End Sub`````` • After that, run the VBA To do that, go to,

Run → Run Sub/UserForm • After running the code, you will be able to count the first day of the joining date as 05-Aug-21 of Emma which has been given in the below screenshot. Read More: Get the First Day of the Current Month in Excel (3 Methods)

### 2. Get the First Day of the Previous Month with Excel VBA

In this method, we will count the first day of the previous month by using the VBA code. This is the easiest and most time-saving way. Let’s follow the steps below to learn!

Step 1:

• According to method 1, insert a new module and type the below VBA code to delete cells. The VBA code is,
``````Sub First_Day_Of_Previous_Month()
strDate = DateValue(Range("C5"))
Range("D5") = DateSerial(Year(strDate), Month(strDate) - 1, 1)
End Sub`````` • Hence, run the VBA To do that, go to,

Run → Run Sub/UserForm Step 2:

• While running the code, you will be able to count the first day of the previous month of the joining date as 05-Aug-21 of Emma which has been given in the below screenshot. Read More: How to Get Last Day of Previous Month in Excel (3 Methods)

### 3. Count the First Day of the Next Month by Running a VBA Code in Excel

After learning how to calculate the first day of the month of a corresponding date and the first day of the previous day of a corresponding date, now, we will count the first day of the next month by using the VBA code. This is the easiest and time-saving way also. Let’s follow the instructions below to learn!

Step 1:

• Similarly, according to method 1, insert a new module and type the below VBA code to delete cells. The VBA code is,
``````Sub First_Day_Of_Next_Month()
strDate = DateValue(Range("C5"))
Range("D5") = DateSerial(Year(strDate), Month(strDate) + 1, 1)
End Sub`````` • Hence, run the VBA To do that, go to,

Run → Run Sub/UserForm Step 2:

• While running the code, you will be able to count the first day of the next month of the joining date as 05-Aug-21 of Emma which has been given in the below screenshot. Read More: How to Convert Date to Month in Excel (6 Easy Methods)

### Bonus: Run a VBA Code to Count the Last Day of the Month in Excel

We will use the EOMONTH function in a VBA code to get the last day of current date. Let’s follow the instructions below.

Steps:

• Put the following code in the visual basic editor to get the last day of the current month in cell C5 of a specific date (2nd Feb 2022) in cell C5.
``````Sub LastDayOfCurrentMonth()
Dim LDay As Double
LDay = Application.WorksheetFunction.EoMonth(Range("C5"), "0")
Range("D5") = VBA.Format(LDay, "mm/dd/yyyy")
End Sub`````` Code Explanation:
• In this code, we put 0 as the LDay to get the last day of the current month.
• We took a variable to hold the output of theWorksheetFunction.EoMonth(Range(“C5”), “0”) which is a date in the form of a serial no. That’s why we used the Format function to set our desired date format ( here, “dd/mm/yyyy”).
• Now press F5 to run the code to get the output. • Hence, you will get 31-08-21 as the last day of the corresponding date. Related Content: How to Get the Last Day of Month Using VBA in Excel (3 Methods)

## Things to Remember

👉 You can pop up Microsoft Visual Basic for Applications window by pressing Alt + F11 simultaneously.

👉 If a Developer tab is not visible in your ribbon, you can make it visible. To do that, go to,

File → Option → Customize Ribbon

## Conclusion

I hope all of the suitable methods mentioned above to count the first day of the month with VBA code will now provoke you to apply them in your Excel spreadsheets with more productivity. You are most welcome to feel free to comment if you have any questions or queries.

## Related Articles #### Md. Abdur Rahim Rasel

Hi! I'm Md. Abdur Rahim Rasel. Welcome to my Profile. Currently, I am working and doing research on Microsoft Excel and here I will be posting articles related to this. I have completed my graduation in Naval Architecture and Marine Engineering(NAME) from Bangladesh University of Engineering and Technology(BUET). I have a passion for learning new things with my knowledge through perseverance and hard work.

We will be happy to hear your thoughts 