Check Column A for Current-Year Dates with Excel VBA
Question details
Check whether column A contains any valid dates in the current calendar year and show a message if none are found.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A VBA procedure needs to scan a dynamic range starting at A2 and ending at the last non-empty cell in column A.
- Observed behavior
- The procedure should display a message and exit when the range contains no current-year dates.
Confirm the worksheet name and whether row 1 is a header; the macro below uses Sheet1 and starts at A2. Open the workbook in a desktop version of Excel that supports VBA, and enable macros only if you trust the file.
Use a VBA loop to check the dynamic date range
Scan column A through its last non-empty cell, skipping blanks and errors, and display a message if no current-year date is found.
The macro uses Excel's system date to determine the current year. It also accepts text that VBA recognizes as a date, which can depend on regional date settings.
In desktop Excel, open the workbook and select Developer > Visual Basic. In the editor, choose Insert > Module.
Paste this code into the module, replacing Sheet1 with your worksheet name if needed: Sub CheckCurrentYearDates() Dim ws As Worksheet Dim lastRow As Long Dim cell As Range Dim value As Variant Dim found As Boolean Set ws = ThisWorkbook.Worksheets("Sheet1") lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row If lastRow >= 2 Then For Each cell In ws.Range("A2:A" & lastRow) value = cell.Value If Not IsError(value) Then If IsDate(value) Then If Year(CDate(value)) = Year(Date) Then found = True Exit For End If End If End If Next cell End If If Not found Then MsgBox "No dates in current year found." Exit Sub End If End Sub
Use File > Save As to save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Then select Developer > Macros, choose CheckCurrentYearDates, and select Run.

Work with date-based spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files and use date formulas in WPS Spreadsheets for an easy transition; Excel VBA macros may require separate compatibility checks.

Frequently Asked Questions
How does the macro find the last row in column A?
It uses ws.Cells(ws.Rows.Count, "A").End(xlUp).Row to find the last non-empty cell in column A, then scans from A2 to that row.
What happens if column A contains blanks or error values?
The macro checks for errors with IsError and tests other values with IsDate. Blanks and values that VBA does not recognize as dates are skipped.
Can I check for current-year dates without VBA?
For dates stored as Excel date values, enter =COUNTIFS(A2:A100,">="&DATE(YEAR(TODAY()),1,1),A2:A100,"<"&DATE(YEAR(TODAY())+1,1,1)) in a cell. A result of 0 means no matching date values were found in that range.
Why does the macro need an .xlsm file?
The .xlsm format preserves VBA code. In Excel, choose File > Save As and select Excel Macro-Enabled Workbook before saving.




