Outlook: How to Count Emails from Specific Sender


Often you may want to count the number of emails from a specific sender in Outlook.

The best way to do so is by writing some code in VBA.

The following step-by-step example shows exactly how to do so.

Note: You do not need any prior knowledge of VBA to use the code in this example. You will simply copy and paste the code provided.

Example: How to Count Emails from Specific Sender in Outlook

First, open Outlook.

Then, type Alt + F11. This will bring up the VBA Editor.

Next, click the Insert tab, then click Module:

Next, paste the following code into the Module window:

Sub CountEmails()
    Dim objNamespace As Outlook.NameSpace
    Dim objFolder As Outlook.Folder
    Dim objItems As Outlook.Items
    Dim objMail As Outlook.MailItem
    Dim senderEmail As String
    Dim startDate As Date
    Dim endDate As Date
    Dim emailCount As Long
    Dim item As Object
    
    emailCount = 0
    senderEmail = InputBox("Enter the sender's email address:", "Sender Email")
    
    If senderEmail = "" Then
        MsgBox "No email address provided. Exiting.", vbExclamation
        Exit Sub
    End If
    
    On Error Resume Next
    startDate = CDate(InputBox("Enter the starting date (MM/DD/YYYY):", "Start Date"))
    On Error GoTo 0
    
    If startDate = 0 Then
        MsgBox "Invalid date provided. Exiting.", vbExclamation
        Exit Sub
    End If
    
    endDate = Date + 1
    
    Set objNamespace = Application.GetNamespace("MAPI")
    Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    Set objItems = objFolder.Items
    
    For Each item In objItems
        If TypeOf item Is Outlook.MailItem Then
            Set objMail = item
            
            If LCase(objMail.SenderEmailAddress) = LCase(senderEmail) Then
                If objMail.ReceivedTime >= startDate And objMail.ReceivedTime <= endDate Then
                    emailCount = emailCount + 1
                End If
            End If
        End If
    Next item
    
    MsgBox "You have received " & emailCount & " email(s) from " & senderEmail & " from " & _
           Format(startDate, "MM/DD/YYYY") & " to " & Format(endDate, "MM/DD/YYYY") & "."
End Sub

Next, close out of the VBA Editor.

Once you’re back in Outlook, type Alt + F8. Then click CountEmails. Then click Run.

Once you click Run, a message box will appear that asks you to specify the email address of the sender:

Once you click OK, another message box will appear that asks you to specify a start date to use for the counting:

Once you click OK, a final message box will appear that tells you how many emails you have received from the specific sender since the specified start date:

Outlook count emails from sender

In this example we can see that we have received 4 total emails from zach@collectingwisdom.com since 5/20/2024.

Feel free to type Alt+F8 to use this VBA code whenever you would like to count the number of emails that you have received from a specific sender.

Related Tutorials

The following tutorials explain how to perform other common tasks in Outlook:

Outlook: How to Search Emails by Date Range
Outlook: How to Search for Multiple Keywords in Emails
Outlook: How to Search for Emails with Attachments

Leave a Reply