VBA & Macro Problems

Count Tasks in Progress by Month in Microsoft Project

Emma BrownEmma Brown Nov 14, 2026 868 views

Question details

Count project tasks in every month between their start and finish dates without relying on a separate custom field for each month.

Count Tasks in Progress by Month in Microsoft Project
Product
Microsoft Project
Device & OS
not provided
Scenario
The user needs dynamic monthly task counts across a long project and prefers to keep the calculation in Microsoft Project.
Observed behavior
A task that starts in an earlier month should still be counted in each later month that overlaps its scheduled dates.
Before you start

Open the project in Microsoft Project and check that the tasks to be counted have valid Start and Finish dates. Run macros only from trusted sources and check your organization's macro security settings.

Solution 1Recommended

Count monthly task overlaps with a Microsoft Project VBA macro

Use this approach to view counts for many months in Project without exporting data or creating monthly custom fields.

The macro counts a task when its scheduled date range overlaps a month. It excludes summary tasks and blank task rows, but includes milestones and completed tasks with valid dates.

The results appear in the VBA Immediate window. They are recalculated when you run the macro again; they are not stored as task fields or updated automatically.

1
Open the VBA editor

In Microsoft Project, open the project you want to analyze and press Alt+F11. In the VBA editor, select Insert > Module.

2
Add the counting macro

Paste this code into the module: Sub CountTasksByMonth() Dim startInput As String, monthsInput As String Dim firstMonth As Date, monthStart As Date, nextMonth As Date Dim monthCount As Long, i As Long, taskCount As Long Dim t As Task startInput = InputBox("Enter a date in the first month to count:") If Not IsDate(startInput) Then Exit Sub firstMonth = DateSerial(Year(CDate(startInput)), Month(CDate(startInput)), 1) monthsInput = InputBox("How many months should be counted? Enter 1 to 1200:", , "36") If Not IsNumeric(monthsInput) Then Exit Sub If Val(monthsInput) < 1 Or Val(monthsInput) > 1200 Then Exit Sub If Val(monthsInput) <> Int(Val(monthsInput)) Then Exit Sub monthCount = CLng(monthsInput) Debug.Print "Month", "Task count" For i = 0 To monthCount - 1 monthStart = DateAdd("m", i, firstMonth) nextMonth = DateAdd("m", 1, monthStart) taskCount = 0 For Each t In ActiveProject.Tasks If Not t Is Nothing Then If Not t.Summary Then If IsDate(t.Start) And IsDate(t.Finish) Then If CDate(t.Start) < nextMonth And CDate(t.Finish) >= monthStart Then taskCount = taskCount + 1 End If End If End If End If Next t Debug.Print Format$(monthStart, "mmm yyyy"), taskCount Next i End Sub

3
Run the macro

Place the cursor inside CountTasksByMonth and press F5. Enter a date in the first month and the number of months to count, such as 36 or 60.

4
View the results

In the VBA editor, press Ctrl+G to open the Immediate window. Read the month and task count pairs there; run the macro again after changing task dates.

Count monthly task overlaps with a Microsoft Project VBA macro
What the count represents: A task is counted for a month if its Start is before the next month and its Finish is on or after the first day of the month. This measures scheduled date overlap, not whether work is actually scheduled or performed during that month.
Free Microsoft Office alternative

Analyze exported project task counts in WPS Spreadsheets

If you later choose to export task data for formulas or charts, WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Excel format compatibility for an easier transition.

Analyze monthly task counts with spreadsheet formulas and chartsOpen and edit Microsoft Excel formats, including XLSXUse a familiar interface for a smoother move from Microsoft OfficeWork with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Does a task that starts before the reporting month get counted?

Yes. The macro counts it if its Finish date is on or after the first day of the reporting month and its Start date is before the following month.

Are summary tasks and milestones included?

Summary tasks are excluded to avoid counting both a summary and its subtasks. Milestones with valid Start and Finish dates are included.

Do the monthly counts update when I change a task date?

Not automatically. Run CountTasksByMonth again from the VBA editor to recalculate the counts using the current project dates.

Where can I see the macro results?

In the VBA editor, press Ctrl+G to open the Immediate window. The macro prints each month and its count there rather than writing the results to custom fields.

Can WPS Spreadsheets run this Microsoft Project macro?

No. The macro uses Microsoft Project task objects and must run in Project. WPS Spreadsheets can instead help analyze task data that has been exported to a compatible spreadsheet format such as XLSX.