从VBA的日期减去? [英] Subtracting from a date in VBA?
问题描述
我有一个表单,其中有一个用户将输入日期的文本框。问题是他可能会以不同的格式输入(例如,8月1日的1.08.2011或同一天的8/1/11)。现在我想做的是减去从他进入TextBox的日期开始的几天。到目前为止我已经取得了成功,我不知道该怎么做。
我尝试过这样的东西
格式((格式(Me.datalivrare.Value,dd.mm.yyy ) - 4),dd.mm.yyyy)
其中datalivrare是那个文本框,其中用户输入日期,4是要从该日期减去的天数...,而且我希望格式始终为dd.mm.yyyy,无论他们在该文本框中输入什么。
我建议查看VBA的DateAdd函数
http://www.techonthenet.com/excel/formulas/dateadd.php
http://office.microsoft.com/en-us/access- help / dateadd-function-HA001228810.aspx
您可以执行以下操作:
格式(DateAdd(d,-4,CDate(Me.datalivrare.Value)),dd.mm.yyyy)
pre>
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.
解决方案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")
这篇关于从VBA的日期减去?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!