Hi all!
I have a problem with the dates.
I have a list of dates that I want to loop through and copy the result to another sheet. The condition is a date range.
Here is my code:
I'd like to use the format "dd.mm.yyyy" everywhere. The list of dates are already set to this format. But when I enter this format to the inputboxes it gives a run-time error '13" type mismatch to the line where I set the "edate"
I've tried to format the inputbox value to the same ( Dim sdate, edate as String, Inputbox("", "start date", Format(Now(), "dd.mm.yyyy")) ), but in that case the error came to the "mydate" line.
I don't know how to set them so they match.
Can someone help?
Thank you.
I have a problem with the dates.
I have a list of dates that I want to loop through and copy the result to another sheet. The condition is a date range.
Here is my code:
VBA Code:
Sub CommandButton1_Click()
Dim lastrow, erow, i As Long
Dim mydate, sdate, edate As Date
sdate = InputBox("", "start date")
edate = InputBox("", "end date")
lastrow = Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("Data").Range("A1").Select
For i = 2 To lastrow 'using headers
mydate = Cells(i, 3)
If mydate >= sdate And mydate <= edate Then
erow = Sheets("Result").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Range(Cells(i, 1), Cells(i, 4)).Copy Destination:=Sheets("Result").Cells(erow, 1)
End If
Next i
End Sub
I'd like to use the format "dd.mm.yyyy" everywhere. The list of dates are already set to this format. But when I enter this format to the inputboxes it gives a run-time error '13" type mismatch to the line where I set the "edate"
I've tried to format the inputbox value to the same ( Dim sdate, edate as String, Inputbox("", "start date", Format(Now(), "dd.mm.yyyy")) ), but in that case the error came to the "mydate" line.
I don't know how to set them so they match.
Can someone help?
Thank you.