我试图通过弹出框向长日期添加 x 天数。
Public Function AskForDeadlinePlus4() As String
Dim strUserResponse As String
strUserResponse = InputBox("Enter Validuntil Date: Add # of Days To Survey end date")
strUserResponse = FormatDateTime(strUserResponse + I2, vbLongDate)
ActiveSheet.Cells(2, 10).Value = strUserResponse 'the 2, 10 is the cell reference for J2 - row 2, column 10.
End Function
调查结束日期位于单元格 I2 中。
当我运行这个时,我得到(谷歌搜索如何做到这一点我很累)
4 + I2
(其中 I2 = 2013 年 4 月 5 日星期五
)>> 1900 年 1 月 3 日星期三
当然我需要2013年4月9日星期二
谢谢
最佳答案
您使用过DateAdd
函数吗?
Sub DateExample()
Dim strUserResponse As String '## capture the user input'
Dim myDate As Date '## the date you want to add to'
Dim numDays As Double '## The number of days you want to add'
strUserResponse = InputBox("Enter Validuntil Date: Add # of Days To Survey end date")
numDays = InputBox("How many days to add?")
myDate = CDate(strUserResponse)
MsgBox DateAdd("d", numDays, myDate)
End Sub
关于date - 在Excel中使用vba向日期添加x天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16259166/