我有一些VBA代码,将日期过滤器应用于数据集以进行进一步的工作。当前,日期过滤器是根据预定义条件应用的:
Worksheets("PSE Data").Activate
StartDate = DateSerial(Year(Date), Month(Date), Day(Date))
EndDate = DateSerial(Year(Date), Month(Date) + 3, Day(Date))
ActiveSheet.ListObjects("PSE_Data").Range.AutoFilter Field:=17, _
Criteria1:=">=" & StartDate, _
Operator:=xlAnd, _
Criteria2:="<=" & EndDate
ActiveSheet.ListObjects("PSE_Data").Range.AutoFilter Field:=6, _
Criteria1:="M"
With ActiveSheet.ListObjects("PSE_Data").Sort
.SortFields.Add Key:= _
Range("PSE_Data" & "[Sugg Start Date]"), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.Apply
End With
我想做的是用弹出框中的用户输入值替换StartDate和EndDate。你能帮忙吗?
这是典型的方式:
Sub dural()
Dim StartDate As Date, EndDate As Date
With Application
StartDate = CDate(.InputBox(Prompt:="enter startdate mm/dd/yyyy", Type:=2))
EndDate = CDate(.InputBox(Prompt:="enter enddate mm/dd/yyyy", Type:=2))
MsgBox StartDate & vbCrLf & EndDate
End With
End Sub
Dim StartDate, EndDate As Date
StartDate = InputBox("Enter start date: ")
EndDate = InputBox("Enter end date: ")