Solved

Filter out records with VBA

Posted on 2015-02-08
5
107 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 51

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

724 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