To remove the time from a date in Excel VBA, use the Int function or the DateValue function: Range("B2").Value = Int(Range("A2").Value) or Range("B2").Value = DateValue(Range("A2").Value). Both return only the date portion (the time becomes midnight), and you can then format the cell as a date to hide the 00:00. This guide shows exactly how to write and run that code, plus the pitfalls that make it look like it failed.
What You'll Need
- Excel for Windows or Mac with the Developer tab enabled (File > Options > Customize Ribbon > check Developer, or Excel > Preferences > Ribbon & Toolbar on Mac).
- A workbook containing cells with date-and-time values (for example
15/03/2024 14:30). - Basic familiarity with opening the VBA editor (Alt+F11 on Windows, Option+F11 on Mac).
Menu labels can differ slightly by Excel version, device and region, but the VBA editor and these functions are consistent across versions.
Step-by-Step
- Open the VBA editor. Press Alt+F11 (Windows) or Option+F11 (Mac). In the Project pane, right-click your workbook and choose Insert > Module. A blank code window appears.
- Write a simple macro. Paste this code, which strips the time from every used cell in column A and writes the date-only value to column B:
Sub RemoveTimeFromDate() Dim r As Range For Each r In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row) If IsDate(r.Value) Then r.Offset(0, 1).Value = Int(r.Value) r.Offset(0, 1).NumberFormat = "dd/mm/yyyy" End If Next r End SubInttruncates the decimal part of the date serial number, which is exactly the time.DateValueworks too but can behave differently with text that looks like a date, soIntis the safer choice for real date values. - Adjust the range and output column. Change
"A2:A"to your source column andOffset(0, 1)to the column where you want the result. To overwrite in place, user.Value = Int(r.Value)instead and skip the Offset line. - Run the macro. Press F5 while the cursor is inside the subroutine, or go back to Excel and use Developer > Macros, select
RemoveTimeFromDate, and click Run. - Format the result cells. Even after removing the time, Excel may display
00:00if the cell format includes time. Select the output cells, press Ctrl+1 (Cmd+1 on Mac), choose Date, and pick a format such asdd/mm/yyyyoryyyy-mm-dd. The underlying value is now a whole number (midnight), so any date format shows only the date. - Verify a few rows. Click a result cell and check the formula bar. A date-only value appears as a date with no time; if you see
15/03/2024 00:00, the format still includes time, not the value.
Common Mistakes
- Formatting instead of converting. Changing the cell format to Date hides the time visually but leaves the decimal in the value. Sorting, filtering or comparing dates can then behave unexpectedly. Use
Intto change the actual value. - Using
CDateorFormat.CDatekeeps the time, andFormat(r.Value, "dd/mm/yyyy")returns text, not a date. Text dates break date arithmetic and sorting. - Forgetting
IsDate. Blank cells, headers and text cause type mismatch errors. The check in the example skips anything that is not a date. - Assuming the output column is empty. The macro overwrites whatever is in the Offset column. Insert a blank column first or change the offset.
- Regional date order.
DateValueinterprets ambiguous text differently by region;Inton a real date value avoids this entirely.
Tips
- To strip time across an entire selection rather than one column, loop over
Selectionand applyIntto each cell. - If your dates are stored as text (left-aligned in the cell), convert them first with
r.Value = CDate(r.Value), then applyInt. - Record a macro while formatting a date cell to capture the exact
NumberFormatstring for your region. - Keep a backup copy before running any macro that overwrites in place; there is no undo for VBA changes.
- For a one-off job, you can also use a helper column with
=INT(A2)and paste values, but the macro is faster for repeated work.
Troubleshooting
- Runtime error 13 (Type mismatch): a cell in the range is not a date. Confirm the
IsDateguard is present and that the range does not include headers. - Results still show a time: the cell format includes time. Apply a date-only format with Ctrl+1.
- Nothing happens: the macro may be in a different module or the workbook may have macros disabled. Check the Trust Center settings and confirm the macro name in Developer > Macros.
- Dates shift by a day: the source may be text interpreted in a different regional order. Convert with
CDatefirst, or use Date > Text to Columns to force the correct order. - Mac vs Windows differences: shortcut keys differ (Option+F11 on Mac), but the VBA functions behave the same.
Frequently Asked Questions
What is the difference between Int and DateValue?
Int truncates the decimal portion of a date serial number, removing the time. DateValue converts a value or text to a date. For genuine date values, both work; Int is more predictable with numeric serials.
Can I remove time without VBA?
Yes. In a helper column use =INT(A2), then copy and Paste Special > Values. Or use Text to Columns with the Date format. VBA is better when you repeat the task often.
Why does my result still show 00:00?
The value is correct (midnight) but the cell format includes time. Change the format to a date-only style.
Will this work on dates stored as text?
Only after converting them. Use CDate or Text to Columns first, then apply Int.
Does removing time affect sorting or filtering?
It improves them. Date-only values sort and filter as whole days, whereas values with times can appear out of order within the same day.
Can I undo a macro that overwrote my data?
No. VBA changes are not covered by Ctrl+Z. Close without saving or restore from a backup if you overwrote source cells.