Solved

Filter out records with VBA

Posted on 2015-02-08
5
105 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

749 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