Solved

Filter out records with VBA

Posted on 2015-02-08
5
103 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 50

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

791 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