If you use autofilter to filter the 'enrolled' items, you can select and copy the rows remaining visible and then paste them to another sheet.Hi,
In my data, I have a column for enrollment status; enrolled or not enrolled. I'm trying to copy only rows that have "enrolled" out of about 200 rows using Excel VBA. Please what do I do?
Thanks for your help!
If you use autofilter to filter the 'enrolled' items, you can select and copy the rows remaining visible and then paste them to another sheet.
with activesheet
with sheets("mydata")
Sub filterToNewSheet()
Dim dataRange As Range, critRange As Range, dumpRange As Range
With ActiveSheet
Set dataRange = .Range("B3", .Cells(Rows.Count, "H").End(xlUp))
End With
With Sheets("sheet2")
Set critRange = .Range("A1:A2")
Set dumpRange = .Range("B1")
End With
critRange(1, 1) = "Enrollment Status"
critRange(2, 1) = "Enrolled"
dataRange.AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=critRange, _
CopyToRange:=dumpRange, _
unique:=False
critRange.EntireColumn.Delete
End Sub