Solved

Filter out records with VBA

Posted on 2015-02-08
5
97 Views
Last Modified: 2016-02-10
How to write a VBA to quickly filter out those records with column C = "Yes" ?

Tks
0
Comment
Question by:AXISHK
5 Comments
 
LVL 5

Assisted Solution

by:magento
magento earned 150 total points
ID: 40597745
Hi ,

Try this please. I used record macro.

Sub Filter()

    Columns("C:C").Select
    Selection.AutoFilter
    ActiveSheet.Range("$C$1:$C$1048576").AutoFilter Field:=1, Criteria1:="Yes"
End Sub

Open in new window


Thanks
0
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 150 total points
ID: 40597772
HI,

If you want to filter Yes out then try

Sub Macro1()
    ActiveSheet.Range(Range("C1"), Range("C" & Cells.Rows.Count).End(xlUp)).AutoFilter _
            Field:=1, Criteria1:="<>*Yes*"
End Sub

Open in new window

Regards
0
 

Author Comment

by:AXISHK
ID: 40597890
Thank, but how to check the last row with column = "Yes" ??
Actually, I want to keep those record with column = Yes only. Tks
0
 
LVL 5

Accepted Solution

by:
Rodney Endriga earned 200 total points
ID: 40609151
Here is VBA code you can use. You can update the COLUMN reference if your data is elsewhere:

Sub EE_FilterYESinColumn()
Dim rng1 As Range

'Change the column<<C>> if data is elsewhere
Set rng1 = ActiveSheet.Range("C1:C" & ActiveSheet.UsedRange.Rows.Count)

For Each cell In rng1
    cell.AutoFilter Field:=1, Criteria1:="Yes"
Next
End Sub
0
 

Author Closing Comment

by:AXISHK
ID: 40620353
Tks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now