Copying rows with specific values

nitar

New Member
Joined
Sep 21, 2011
Messages
7
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!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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.
 
Upvote 0
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.

Thanks Weaver,
I have tried recording the macro, I would just like something more advanced if there is :).
 
Upvote 0
Most VB solutions for this task are based on the filtering method, so with a few tweaks, the recorded macro should be where you'll end up. You might also be able to use the advanced filter, but that needs a bit of setting up beforehand


What's the start/end columns of the data? what row is the header in? what column is the criteria in? What's the criteria header (in case we go with the advanced filter method) and finally where's the data going?
 
Upvote 0
OK, thanks. See below:
Start:End Column - 2:8
Header Row - 3
Criteria Column - 8
Criteria Header - Enrollment Status
New location - The next sheet (i.e. Sheet2)
 
Upvote 0
Try this. Change sheet names where required. You should have the data tab selected when you run it, although you could change this by changing
Code:
with activesheet
to
Code:
with sheets("mydata")
Code:
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
It also assumes sheet2 is as yet unpopulated.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,894
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top