hi,
i want to know the error in the below code. i am applying this code to copy data from sheet2 to sheet1 based on DATE criteria.
Sub CommandButton1()
Dim lastrow, i, erow As Integer
Dim sh As Worksheet
Dim cell As Range
Dim sheets As Worksheet
Set sheets = ActiveWorkbook.Worksheets("sheet2")
lastrow = sheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If cell(i, 1) = "29/10/1993" Then
Range(Cells(i, 1), Cells(i, 3)).Select
Selection.Copy
Set sh = ActiveWorkbook.Worksheets("sheet1")
sheets("Sheet1").Select
erow = sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
sheets("Sheet1").Cells(erow, 1).Select
ActiveSheet.Paste
End If
Next i
End Sub
i want to know the error in the below code. i am applying this code to copy data from sheet2 to sheet1 based on DATE criteria.
Sub CommandButton1()
Dim lastrow, i, erow As Integer
Dim sh As Worksheet
Dim cell As Range
Dim sheets As Worksheet
Set sheets = ActiveWorkbook.Worksheets("sheet2")
lastrow = sheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If cell(i, 1) = "29/10/1993" Then
Range(Cells(i, 1), Cells(i, 3)).Select
Selection.Copy
Set sh = ActiveWorkbook.Worksheets("sheet1")
sheets("Sheet1").Select
erow = sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
sheets("Sheet1").Cells(erow, 1).Select
ActiveSheet.Paste
End If
Next i
End Sub