Forum Discussion

hrh_dash's avatar
hrh_dash
Iron Contributor
Sep 23, 2022
Solved

how to filter cells if cells contains specific text vba

How do i amend the code below to filter specific text such as "PTE." , "LTD.", "PRIVATE", "LIMITED", "LLP"?

 

Option Compare Text

Sub sort ()    
    Dim ws          As Worksheet
    Dim rng         As Range
    
    Set rng = Selection
    Set ws = ThisWorkbook.Sheets("GTL_LOD")

     rng.AutoFilter Field:=4, Criteria1:=Array("*ENT*", "*LIMITED*", "*LTD*"), Operator:=xlFilterValues
    'ws.AutoFilter.Range.Offset(1, 0).Rows.SpecialCells(xlCellTypeVisible).Delete (xlShiftUp)
    'ws.ShowAllData

End Sub

 

appreciate the help in advance!

  • hrh_dash 

    Maybe I´m wrong, the problem is that you want to filter any word that contains "PTE." , "LTD.", "PRIVATE", "LIMITED", "LLP".

    I was looking online and what I found is that you can only filter for 2 values when using wildcards.

     

    Also, find this one where they explain how to make it work. Attached is an example, hope it works.

    https://www.mrexcel.com/board/threads/wild-card-unable-to-use-in-autofilter-array.917998/

     

2 Replies

  • alannavarro's avatar
    alannavarro
    Iron Contributor

    hrh_dash 

    Maybe I´m wrong, the problem is that you want to filter any word that contains "PTE." , "LTD.", "PRIVATE", "LIMITED", "LLP".

    I was looking online and what I found is that you can only filter for 2 values when using wildcards.

     

    Also, find this one where they explain how to make it work. Attached is an example, hope it works.

    https://www.mrexcel.com/board/threads/wild-card-unable-to-use-in-autofilter-array.917998/

     

Resources