sophieschrit
10-13-2015, 06:03 AM
Hi all,
I'm new on VBA and I'm trying to find a solution for my problem. So basically want I want to do is to filter all the data between two exact dates which I get from an inputbox. So I can only keep the payout dates from one week. At the beginning it worked fine but then I saw that I'll have problems if the dates are from two months. I also tried to do it with an Array but didn't worked. I really hope some one can help me as I'm now getting really frustrated :(
Here is my beloved part of the macro and I also attach the worksheet.
Thank you so much for helping me
Sub filtertry()
Dim EndDate0 As Date
Dim EndDate As String
Dim StartDate0 As Date
Dim StartDate As String
ActiveSheet.Name = "Settlement Overview"
EndDate = InputBox("Please insert Enddate", Hi, Format(Now, "dd.mm.yyyy"))
EndDate0 = CDate(EndDate)
StartDate0 = EndDate0 - 4
StartDate = Format(StartDate0, "dd.mm.yyyy")
ActiveSheet.Range("A8").End(xlDown).End(xlToRight).Select
Selection.AutoFilter Field:=4, Criteria1:=">=" & "StartDate", Operator:=xlAnd, Criteria2:="<=" & "EndDate", Operator:=xlFilterValues
End Sub
I'm new on VBA and I'm trying to find a solution for my problem. So basically want I want to do is to filter all the data between two exact dates which I get from an inputbox. So I can only keep the payout dates from one week. At the beginning it worked fine but then I saw that I'll have problems if the dates are from two months. I also tried to do it with an Array but didn't worked. I really hope some one can help me as I'm now getting really frustrated :(
Here is my beloved part of the macro and I also attach the worksheet.
Thank you so much for helping me
Sub filtertry()
Dim EndDate0 As Date
Dim EndDate As String
Dim StartDate0 As Date
Dim StartDate As String
ActiveSheet.Name = "Settlement Overview"
EndDate = InputBox("Please insert Enddate", Hi, Format(Now, "dd.mm.yyyy"))
EndDate0 = CDate(EndDate)
StartDate0 = EndDate0 - 4
StartDate = Format(StartDate0, "dd.mm.yyyy")
ActiveSheet.Range("A8").End(xlDown).End(xlToRight).Select
Selection.AutoFilter Field:=4, Criteria1:=">=" & "StartDate", Operator:=xlAnd, Criteria2:="<=" & "EndDate", Operator:=xlFilterValues
End Sub