abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,429
- Office Version
- 2019
- 2010
- Platform
- Windows
hello
i do a simple code but it gives me error to search data betwwen dates the sheet1 contains data from a7:d and i would search into sheet2 first date = c2 end date= c3 and gives me data from sheet1 to sheet2 in this range (a2:d7) i hope anybody fixing my code i would the result in image 2
i do a simple code but it gives me error to search data betwwen dates the sheet1 contains data from a7:d and i would search into sheet2 first date = c2 end date= c3 and gives me data from sheet1 to sheet2 in this range (a2:d7) i hope anybody fixing my code i would the result in image 2
VBA Code:
Sub test()
Dim i As Long
Dim Startdate As Date
Dim Enddate As Date
LASTROW = Cells(Rows.Count, 1).End(xlUp).Row
Startdate = SHEET2.Range("c2").Value
Enddate = SHEET2.Range("c3").Value
For i = 7 To LASTROW
If sheet1.Range("A7:d" & i).Value >= Startdate And sheet1.Range("A7:d" & i).Value <= Enddate Then
sheet1.Range("a7:d" & i + 1).Value = sheet1.Range("a7:d" & i).Value
End If
Next i
End Sub