I tried to make a VBA that copies the rows containing a specific value to another worksheet. I came across the guy on youtube (https://www.youtube.com/watch?v=-QFjJoRGCtU&t=332s) and followed his formulas. When I try to run it, it only copy&paste the 1st row to another worksheet. I'm guessing that I didn't define the finalrow
properly that's why it failed. Care to fix my code for me?
Here's my code:
Sub Search_Extract()
Dim resultnumber As Integer
Dim finalrow As Long
Dim datasheet As Worksheet, reportsheet As Worksheet
Dim i As Integer 'rowcounter
Set datasheet = Sheet4
Set reportsheet = Sheet3
resultnumber = reportsheet.Range("A1").Value
reportsheet.Range("D5:F7000").ClearContents
datasheet.Select
finalrow = Cells(Rows.Count, 3).End(xlUp).Row
For i = 1 To finalrow
If Cells(i, 3) = resultnumber Then
Range(Cells(i, 1), Cells(i, 3)).Copy
reportsheet.Select
Range("D6700").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
Next i
reportsheet.Select
End Sub