gpt4 book ai didi

date - 在Excel中使用vba向日期添加x天数

转载 作者:行者123 更新时间:2023-12-02 03:00:42 25 4
gpt4 key购买 nike

我试图通过弹出框向长日期添加 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com