Subtracting from a date in VBA?

calendar_today Asked Aug 8, 2011
thumb_up 18 upvotes
history Updated April 14, 2026

Direct Answer

I suggest looking at the DateAdd function for VBA http://www.techonthenet.com/excel/formulas/dateadd.php…. This is an advisory response with reference links, ranked #26th of 95 by community upvote score, from 2011.


The Problem (Q-score 9, ranked #26th of 95 in the VBA Core archive)

The scenario as originally posted in 2011

I’m having big problems doing operation with the date in Excel VBA.
I have a form that has a textbox where the user will enter the date. The problem is that he may enter it in different formats (eg, 1.08.2011 for 1st of August, or 8/1/11 for the same day). Now what I want to do is to subtract some days from that date that he enters in the TextBox. I had to success so far and I don’t know how to do it.
I tried something like this

Format((Format(Me.datalivrare.Value, "dd.mm.yyy") - 4), "dd.mm.yyyy")

Where datalivrare is that textbox where the user enters the date and 4 is the number of days I want to subtract from that date… and I want the format to always be dd.mm.yyyy no matter what they enter in that textbox.

Why community consensus is tight on this one

Across 95 VBA Core entries in the archive, the accepted answer here holds strong answer (top 25 %%) status — meaning voters are unusually aligned on the right fix.


The Verified Solution — strong answer (top 25 %%) (+18)

Advisory answer — community consensus with reference links

Note: the verified answer below is a reference / advisory response rather than a copy-ready snippet.

I suggest looking at the DateAdd function for VBA

http://www.techonthenet.com/excel/formulas/dateadd.php

http://office.microsoft.com/en-us/access-help/dateadd-function-HA001228810.aspx

You could do the following:

Format(DateAdd("d", -4, CDate(Me.datalivrare.Value)), "dd.mm.yyyy")


When to Use It — vintage (14+ years old, pre-2013)

Ranked #26th in its category — specialized fit

This pattern sits in the 85% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the VBA Core archive for a higher-consensus alternative.

What changed between 2011 and 2026

The answer is 15 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

Why does this sit in the top quartile of VBA Core answers?
expand_more

Answer score +18 vs the VBA Core archive median ~6; this entry is strong. The score plus 9 supporting upvotes on the question itself (+9) means the asker and 17 subsequent voters all validated the approach.

This answer links out — what are the reference links worth following?
expand_more

Read the first external link for the canonical reference, then search this archive for a top-10 entry in the same category — advisory answers are best paired with a ranked code snippet to close the loop.

This answer is 15 years old. Is it still relevant in 2026?
expand_more

Published 2011, which is 15 year(s) before today’s Office 2026 build. The VBA Core object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which VBA Core pattern ranks just above this one at #25?
expand_more

The pattern one rank above is “best content on how to deploy and share a VSTO solution”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 9, Answer-score 18, original post 2011, ranked #26th of 95 in the VBA Core archive. Last regenerated April 14, 2026.

vba