我想用一个弹出框将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 = Friday, April 05, 2013
)>> Wednesday, January 03, 1900
当然我需要
Tuesday, April 09, 2013
谢谢
最佳答案
您是否使用过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