Hi!
Im trying to extract specific data between two dates into another sheet with userform. But I dont know what im doing wrong..
all help is welcome.
error.JPG
Private Sub CommandButton1_Click()
Dim lrow As Long, i As Long, x As Date, y As Date, erow As Long
x = TextBox1
y = TextBox2
'Find the Last Row (data filled row) of Sheet1
lrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
'start counting from row 2 to last row
For i = 2 To lrow
' here the date balue is converted as numeric value by multiplying with number 1
If Cells(i, 1) * 1 >= x * 1 Then
If Cells(i, 1) * 1 >= y * 1 Then
' here i,3(the column number where Artikel found
If Trim(Cells(i, 3)) = Trim(TextBox3.Text) Then
'if above conditions matched then select the matched range or entire row
Sheet1.Range(Cells(i, 1), Cells(i, 4)).Select
'to copy the selected row
Selection.Copy
'to make sheet2 active where we want to paste the selected row
Sheets("Sheet2").Activate
'to find the empty row from where the copide row of sheet1 to be pasted in sheet2
erow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'to activate or select the empty row of sheet2
ActiveSheet.Cells(erow, 1).Select
'to paste the copied row
ActiveSheet.Paste
'to deselect the copy and selected mode
Application.CutCopyMode = False
'for above the if we need 3 end if to close if conditions
End If
End If
End If
'finally to activate sheet1 for searching the mached data
Sheets("Sheet1").Activate
'now to continue for look until above matched found
Next i
End Sub
Bookmarks