Hello, I'm looking for a way to filter out rows of data based on a value in a cell. Currently my worksheet uses formulae to put "Keep" in a column next to each row of data that needs to be kept, leaving data to be discarded blank. I found and altered a macro which should transfer only the rows which have "Keep" in the status column to a new worksheet, but instead it is counting the number of "Keep" values and copying the same number of rows consecutively starting from the top.
In other words, out of 10000 rows, 4000 say "Keep" with 6000 blanks mixed up in between them. Instead of skipping the blanks, my macro is just copying the first 4000 rows of data. Can anyone help me alter or write new code to do this? I also have the VBA course which I'm working through, but can anyone suggest which specific videos might be helpful for this sort of task?
Sub CopyIfKeepExample()
Dim lastrowRS As Long
Dim StatusCol, Status, PasteCell As Range
lastrowRS = Sheet11.Cells(1, 1).End(xlDown).CurrentRegion.Rows.Count
'Sheet name and range holding the data to copy rows from.
Set StatusCol = Sheet11.Range("F2:F" & lastrowRS & "")
For Each Status In StatusCol
If Sheet17.Range("A2") = "" Then
Set PasteCell = Sheet17.Range("A2")
Else
Set PasteCell = Sheet17.Range("A1").End(xlDown).Offset(1, 0)
End If
'"Keep" criterion is in column 5, five cells per record
If Status = "Keep" Then Status.Offset(0, -5).Resize(1, 4).Copy PasteCell
Next Status
Worksheets.Sheet17.Activate
MsgBox "Transfer Complete"
End If
End Sub