我有一个用户输入的变量(rptdate(。我想创建一个比rptdate早7天的另一个变量(startdate(。
*我计划使用结束日期,因此除了其他变量之外,它已经在下面创建
Dim rptdate As Variant
Dim StartDate As Variant
Dim enddate As Variant
rptdate = InputBox("enter report date")
enddate = Format(rptdate, "mmmm d,yyyy")
StartDate = DateAdd(D, -7, enddate)
InputBox总是返回文本,所以试试这个:
Dim rptInput As String
Dim rptDate As Date
Dim StartDate As String
Dim EndDate As String
rptInput = InputBox("Enter report date")
If IsDate(rptInput) Then
rptDate = DateValue(rptInput)
EndDate = Format(rptDate, "mmmm d, yyyy")
StartDate = Format(DateAdd("d", -7, rptDate), "mmmm d, yyyy")
End If