# VBA: Create a group of Year and Month in Outlook

* Create a **New Colum** which name "**GroupY**" and "**GroupYM**"
* Open the Microsoft Visual Basic for Applications from "Developer" tab
* Insert > Module&#x20;
* &#x20;Use VBA macro into the module:

```
Sub ListSelectionYearAndMonth()
    Dim aObj As Object
    Dim oProp As Outlook.UserProperty
    Dim sMonth
    Dim sYear
    
    On Error Resume Next
    
    For Each aObj In Application.ActiveExplorer.Selection
        Set oMail = aObj
        
        sMonth = Month(oMail.ReceivedTime)
        sYear = Year(oMail.ReceivedTime)
        Set oProp = oMail.UserProperties.Add("GroupY", olText, True)
        oProp.Value = sYear
        Set oProp = oMail.UserProperties.Add("GroupYM", olText, True)
        oProp.Value = Join(Array(sYear, "-", sMonth))
        
        oMail.Save
        
        Err.Clear
    Next
    
End Sub

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://code.cyberchamp.net/outlook/vba-create-a-group-of-year-and-month-in-outlook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
