+ Reply to Thread
Results 1 to 7 of 7

Macro for Filtering Data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-18-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    192

    Macro for Filtering Data

    Hi Friends

    I have attached the file in which I want to filter the data where it does not contain 101, 102, 1022, 1023, 103, 104, 1055, 107, 1078, 110, 111.

    The rest of the rows except the above should be deleted. Can you please help me writing macro?

    Many thanks in advance.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    07-10-2016
    Location
    Saudi Arabia
    MS-Off Ver
    2016
    Posts
    2

    Re: Macro for Filtering Data

    Hi arpanpanchal,

    Try the following code and let me know if this is what you want.

    Sub ArpanpanchalNumbers()
    Dim ListCounts As Long
    ListCounts = Range("A1", Range("A1").End(xlDown)).Rows.Count
    For i = 2 To ListCounts
    Select Case Cells(i, "A")
    Case 101
    Case 102
    Case 1022
    Case 1023
    Case 103
    Case 104
    Case 1055
    Case 107
    Case 1078
    Case 110
    Case 111
    Case Else
    Cells(i, "A") = ""
    End Select
    Next i
    End Sub

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro for Filtering Data

    This should do
    Sub test()
        With Cells(1).CurrentRegion
            .AutoFilter 1, Split("101,102,1022,1023,103,104, 1055,107,1078,110,111", ","), 7
            On Error Resume Next
            .SpecialCells(12).Select
            .AutoFilter
            Selection.EntireRow.Hidden = True
            .SpecialCells(12).EntireRow.Delete
            On Error GoTo 0
            .Rows.Hidden = False
            .Cells(1).Select
        End With
    End Sub
    Last edited by jindon; 07-11-2016 at 03:07 AM.

  4. #4
    Forum Contributor
    Join Date
    07-18-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    192

    Re: Macro for Filtering Data

    Hi Jindon

    Thanks a lot. It works as I wanted. Can I please ask you to explain few things in your code as I am learning vba? Why did you use 7 after Split function and what is the meaning of SpecialCells(12)?

    Thanks again for your assistance.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro for Filtering Data

    1) 7 for Operator protocol of AutoFilter is xlFilterValues and this is not optional when criteria is an array.
    2) 12 for Type protocol of SpecialCells is xlCellTypeVisible.

    Helped?

  6. #6
    Forum Contributor
    Join Date
    07-18-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    192

    Thumbs up Re: Macro for Filtering Data

    Hi Jindon

    That make sense now.

    Again, thank a lot for your time and effort.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro for Filtering Data

    You are welcome and thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro for filtering data
    By ldurham in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2016, 09:19 AM
  2. Macro filtering and copying data
    By celeazul in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-29-2015, 02:11 PM
  3. Non functioning Data Filtering Macro
    By Cupragsw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2014, 06:31 AM
  4. Macro For Filtering And Pasting Data
    By excellearner121 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-07-2013, 11:49 PM
  5. Help about macro and filtering data
    By bitaz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2011, 02:14 AM
  6. HELP-- Filtering and copying data to a new sheet (w/ macro)
    By Voldemore in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-17-2005, 05:05 PM
  7. filtering data with a macro
    By Jack in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2005, 12:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1