将x天数添加到Excel中的vba日期 [英] Add x number of days to a date with vba in excel

查看:439
本文介绍了将x天数添加到Excel中的vba日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公共功能AskForDeadlinePlus4( )As String 
Dim strUserResponse As String

strUserResponse = InputBox(Enter Validuntil Date:Add Days of Days To Survey end date)
strUserResponse = FormatDateTime(strUserResponse + I2, vbLongDate)
ActiveSheet.Cells(2,10).Value = strUserResponse'2,10是J2 - 第2行第10列的单元格引用。

结束函数

细胞I2中调查结束日期。



当我运行这个我得到(谷歌如何做这个我很累)



4 + I2 (其中 I2 = 2013年4月5日星期五> 1900年1月3日星期三



当然我需要 2013年4月9日星期二



谢谢

解决方案

您是否使用了 DateAdd 函数? / p>

  Sub DateExample()

Dim strUserResponse As String'##捕获用户输入'
Dim myDate As Date'##你要添加到'
的日期Dim dDD as As''你要添加的天数'


strUserResponse = InputBox(Enter Validuntil Date:Add Days of Survey To Survey end date)
numDays = InputBox(要添加多少天?)
myDate = CDate(strUserResponse)

MsgBox DateAdd(d,numDays,myDate)


End Sub


I am tring to add x number of days to a Long date with a pop up box.

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

Where Survey end date in cell I2.

When I run this I get (Googling how to do this I am tiring)

4 + I2 (where I2 = Friday, April 05, 2013) >> Wednesday, January 03, 1900

of course I need Tuesday, April 09, 2013

Thanks

解决方案

Have you used the DateAdd function?

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

这篇关于将x天数添加到Excel中的vba日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆