To find a cell containing a specific date with Excel VBA, loop through the date column and compare each cell’s numeric date serial with the target date. The macro below finds the first date on a calendar day, even if the cell also contains a time, and selects the matching cell.
What Excel Stores as a Date
Excel dates are numbers displayed using a date format. A cell that displays as March 8, 2025, contains a serial number; if it also contains a time, the time is stored as a fractional part of that number. For example, two cells can both display March 8 while holding different values because one includes a time such as 9:30 a.m.
This distinction matters when searching. A comparison for exact equality can miss a cell that contains the requested date plus a time. Conversely, searching for the displayed text can depend on the cell’s number format and regional date settings. For a date-column search that should treat all times on the same day as a match, compare the whole-number date portion of each serial.
The code below assumes the dates are actual Excel date values in a date column. It deliberately ignores text that looks like a date: text needs parsing, and its interpretation can vary with Windows regional settings. If you need to search text dates, see the troubleshooting section before changing the comparison.
Macro to Find the First Matching Date
In the example, the worksheet is named Data, the search range is A2:A500, and the target is March 8, 2025. Change those three details to match your workbook. The macro checks every cell in the range, returns the first match in top-to-bottom order, and displays its address.
Sub FindDateInColumn()
Dim ws As Worksheet
Dim searchRange As Range
Dim cell As Range
Dim targetDate As Date
Dim targetSerial As Double
' Set the worksheet, range, and calendar date to find.
Set ws = ThisWorkbook.Worksheets("Data")
Set searchRange = ws.Range("A2:A500")
targetDate = DateSerial(2025, 3, 8)
' Adjust for workbooks that use the 1904 date system.
targetSerial = CDbl(targetDate)
If ws.Parent.Date1904 Then targetSerial = targetSerial - 1462
For Each cell In searchRange.Cells
If Not IsError(cell.Value2) Then
' Value2 exposes stored serials; skip text that resembles a date.
If VarType(cell.Value2) <> vbString And IsNumeric(cell.Value2) Then
If Int(CDbl(cell.Value2)) = targetSerial Then
Application.Goto Reference:=cell, Scroll:=True
MsgBox "Date found in " & cell.Address(False, False)
Exit Sub
End If
End If
End If
Next cell
MsgBox "Date not found in " & searchRange.Address(False, False)
End Sub
Before running a macro, save a copy of the workbook. VBA actions cannot be undone with Ctrl+Z. To add and run the code in Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, choose Insert > Module, paste the code, then run FindDateInColumn. If Excel blocks macros, save the file in a macro-enabled format such as .xlsm and follow your organization’s macro-security rules. On Mac, use Option+F11 or open the Visual Basic Editor through the Developer tab; available shortcuts can vary by keyboard and Excel settings.
How the Date Comparison Works
DateSerial(2025, 3, 8) creates a VBA date for the specified year, month, and day without relying on how a typed date string is interpreted. The macro converts that target to a serial number, then uses Int on each cell’s numeric value to discard any fractional time portion. A value for March 8 at 9:30 a.m. therefore matches the target date for March 8.
Excel workbooks can use either the 1900 or 1904 date system. The same calendar date has serial numbers 1,462 days apart between those systems. The Date1904 check adjusts the target serial when the searched workbook uses the 1904 system; without it, a macro that compares raw serials can report the wrong match in that kind of workbook.
The loop stops at the first match. If the date appears in several rows, only the first cell is selected and reported. The comparison is intentionally based on the day, not the exact timestamp. A column formatted as a date is helpful for people reading the sheet, but the macro’s comparison uses stored values rather than the display format.
Set the Worksheet and Search Range
Replace Data with the exact worksheet tab name, including spaces and punctuation, and change A2:A500 to the cells you want to inspect. The worksheet name in the VBA code must match the tab name; otherwise VBA will stop with a “Subscript out of range” error. If the sheet belongs to a different workbook than the one containing the macro, change the workbook reference too. ThisWorkbook means the workbook where the code is stored, not necessarily the workbook currently active on screen.
For a search that should cover every used row in column A, you can set the range dynamically instead of choosing a fixed last row. A common pattern is to find the last nonempty cell in that column with the Range.End property, then build the range from A2 to that cell. This is useful when rows are added regularly, but account for an empty column: if there are no dates below the header, a last-row calculation can point to the header or return an unexpected range.
You can also search a selected portion of a worksheet, or a range on another sheet, by setting searchRange to the appropriate range. Keep the range limited to the date data where possible. Searching an entire worksheet takes longer and can produce a match in an unrelated numeric cell, because Excel does not store a distinct “date” data type separate from ordinary numbers.
Finding an Exact Date and Time Instead
If the time is part of what you need to match, do not remove the fractional portion with Int. Instead, compare the complete serial value against a target that includes the time. For example, build the target with DateSerial plus TimeSerial, and compare the cell value to that target using a tolerance if the values may have been calculated. Floating-point representation can make exact equality unreliable for computed date-time values.
For an exact time match, first decide whether the source values are entered directly or produced by formulas. Directly entered date-times may compare cleanly, but calculations can introduce tiny numerical differences. A practical approach is to compare whether the absolute difference between the cell’s serial and the target serial is below a small tolerance appropriate to the time precision you care about. Do not use the calendar-day comparison in the supplied macro for this task: it intentionally treats all times on the same date as equal.
Using Find and Choosing the Right Method
Excel’s Range.Find method is useful when you want Excel’s built-in search behavior and are looking for a particular cell value. Its settings include LookIn, LookAt, SearchOrder, and SearchDirection. Because Find remembers some options from earlier searches and the Excel Find dialog, reliable VBA should specify the relevant arguments each time rather than rely on whatever settings were last used.
Dates make Find less straightforward than ordinary text. A date is a serial number, while the user sees formatted text; a time may be part of the value even when it is hidden. Find may therefore be unsuitable when the requirement is “any time on this calendar day.” The explicit loop is easier to adapt for that rule, to skip errors, and to report the first match. Use Find when exact search semantics fit your data; use a loop when you need date-specific logic or want to inspect every candidate.
Neither approach can reliably infer that an arbitrary number is intended to be a date. If the search range mixes dates, prices, IDs, or other numbers, restrict the range to the date field or add a separate check based on your workbook’s structure. Formatting a number as a date changes how it appears, not what it represents.
Common Problems and Fixes
- No match despite an apparent match: Check whether the cell is a true date serial or text, and whether it includes a time. The macro handles time fractions but skips text values.
- Wrong date appears to match: Make sure the range contains only the intended date data. Other numeric values can share a date serial, and Excel does not attach a separate date type to them.
- Run-time error on the worksheet reference: Check the spelling of the sheet tab name and confirm the intended workbook is open. ThisWorkbook refers to the workbook containing the macro.
- Dates are stored as text: Convert them to real dates before searching, or parse the text using a known format. Do not assume that CDate will interpret ambiguous strings such as 03/08/2025 the same way on every computer.
- Macro does not run: Confirm the code is in a standard module, the file is saved as .xlsm if necessary, and your security settings allow the macro. Do not enable macros from an untrusted file.
If your workbook uses text dates in a consistent format, conversion is usually the cleanest solution. For example, use Excel’s date conversion tools or a carefully designed parsing routine, then verify the results before searching. A string such as 2025-03-08 is less ambiguous than 03/08/2025, but text still is not the same thing as an Excel date serial.
Frequently Asked Questions
How do I find a date in Excel VBA and select the cell? Loop through the relevant date range, compare each cell with the target date, and use Application.Goto or select the matched cell. The example macro uses Application.Goto to navigate to its first match.
How can I find a date when cells also contain times? Compare the integer portion of each date serial to the target date serial. The macro uses Int for that reason, so every time on the requested calendar day counts as a match.
Can VBA find a date that is stored as text? It can, but the text must be parsed or compared as text using a known format. Parsing strings such as 03/08/2025 can produce different results under different regional settings, so converting the column to real dates is generally safer.
Why does Find miss a date that is visible in the cell? The displayed date may hide a time fraction, or Find may be comparing a value differently from the way the cell is formatted. Check the underlying value and use a loop that compares calendar dates when any time on that date should qualify.
How do I find every cell with that date, not just the first? Remove the first-match exit behavior and continue through the range after each match, collecting addresses or highlighting cells. Decide how to report multiple matches before changing the macro, especially if the search range is large.
Related
- Excel Page Break Lines Won’t Go Away? How to Hide Them
- Excel Page Break Dotted Lines: Meaning and Fixes Explained
- Excel Page Break Header: Repeat Headings on Every Page
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA: Protect a Sheet and Allow Filter and SortYes. In Excel VBA, protect the worksheet with AllowFiltering:=True and AllowSorting:=True. The filter controls must already exist, and…
- Macro Recorder for Games: How It Works and What to KnowA macro recorder for games captures a sequence of keyboard or mouse inputs and replays them, often with…
- VBA Delete Rows With a Specific Cell Value in ExcelTo delete Excel rows when a cell in a chosen column contains a specific value, loop upward from…
- VBA MsgBox Sound: What Triggers It and How to Control ItIn Excel VBA, MsgBox has no argument for choosing or setting a sound. On Windows, a message box…
- Excel VBA: Hide a Column by Number in Your WorksheetTo hide a column by its number in Excel VBA, set that worksheet column’s Hidden property to True.…
- Filter Dictionary Keys in Excel VBA: Code and OptionsYes. In Excel VBA, filter a Scripting.Dictionary by looping through its keys and copying the matching key/value pairs…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.