How To Enter the holiday according to the Table in the holiday list using VBA?
Tags: toentertheholidayacc, vbamacros
Published: 2021-10-05 11:13:28

---
title: How To Enter the holiday according to the Table in the holiday list using VBA?
published: true
date: 2021-10-04 11:37:53 UTC
tags: ToEnterTheHolidayAcc,VBAMacros
canonical_url: https://geekexcel.com/how-to-enter-the-holiday-according-to-the-table-in-the-holiday-list-using-vba/
---

In this article, you will learn how to ** enter the holiday according to the table in the holiday list using VBA ** in Microsoft 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  **EmployeeName, the HolidayStart and the HolidayEnd** in a Worksheet.

![](https://geekexcel.com/wp-content/uploads/2021/10/Sample-data-8.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.

```
Sub NewVacation()
   Dim rngFind As Range
   Dim intRow As Integer, intMonth As Integer, intCounter As Integer
   intRow = 3
   Do Until IsEmpty(Cells(intRow, 1))
      For intMonth = Month(Cells(intRow, 2)) To Month(Cells(intRow, 3))
         Set rngFind = Worksheets(Format(DateSerial(1, intMonth, 1), "mmmm")). _
            Columns(1).Find _
            (Cells(intRow, 1), LookIn:=xlValues, lookat:=xlWhole)
         If intMonth = Month(Cells(intRow, 2)) And intMonth = _
            Month(Cells(intRow, 3)) Then
            For intCounter = Day(Cells(intRow, 2)) To Day(Cells(intRow, 3))
               rngFind.Offset(0, intCounter).Interior.ColorIndex = 3
            Next intCounter
         ElseIf intMonth = Month(Cells(intRow, 2)) Then
            For intCounter = Day(Cells(intRow, 2)) To Day(DateSerial _
               (1, Month(Cells(intRow, 2)) + 1, 0))
               rngFind.Offset(0, intCounter).Interior.ColorIndex = 3
            Next intCounter
         Else
            For intCounter = 1 To Day(Cells(intRow, 3))
               rngFind.Offset(0, intCounter).Interior.ColorIndex = 3
            Next intCounter
         End If
      Next intMonth
      intRow = intRow + 1
   Loop
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-6-1024x701.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-7.png)<figcaption>Run the Code</figcaption>

- Finally, you will receive  **output as according to the table in the holiday list**  using VBA.

## Summary

We hope that this short tutorial gives you guidelines on how to  **enter the holiday according to the table in the holiday list 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/) **!!**

**Read Ahead:**

- **[How to use Excel NETWORKDAYS Function in Office 365?](https://geekexcel.com/how-to-use-networkdays-function-in-ms-excel-365/)**
- **[Excel Shortcut: INSERT TABLE in the Worksheet in Excel 365!!](https://geekexcel.com/ms-excel-shortcut-to-insert-table-in-the-worksheet/)**
- **[Shortcut to SELECT TABLE in Microsoft Excel 365!](https://geekexcel.com/keyboard-shortcut-to-select-table-in-microsoft-excel-365/)**
- **[Excel Formulas to Count the Values that appear in a List!!](https://geekexcel.com/excel-formulas-to-count-the-values-that-appear-in-a-list/)**
- **[Convert a Table to the Data Range in Excel Office 365!](https://geekexcel.com/convert-table-to-data-range/)** [!](https://geekexcel.com/convert-table-to-data-range/)