+ Reply to Thread
Results 1 to 10 of 10

Filter Range

  1. #1
    Registered User
    Join Date
    10-12-2019
    Location
    USA
    MS-Off Ver
    360
    Posts
    48

    Filter Range

    Hello,
    I can filter strings in any column but not numbers in the table.
    Can someone help me.

    Please Login or Register  to view this content.
    Thans for any help

  2. #2
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Filter Range

    Hello. Let's guess:

    a) Apparently, you have your TextBox1 "floating" above the active sheet.
    b) Via 'LinkedCell', this TextBox1 appears to be linked to cell E3: this is not necessary to articulate the filter.
    c) It seems that you write a number in TextBox1 that is part of a number with more digits.
    d) The latter means that AutoFilter is not the right tool to filter your list.
    e) You have to use the Advanced Filter as follows:

    PHP Code: 
    Option Explicit
    Dim tbl 
    As ListObject

    Private Sub TextBox1_Change()
    Dim C As Range
    Set tbl 
    ListObjects("EmpList"): tbl.Range.AutoFilter
    Set C 
    tbl.DataBodyRange.Find(What:=TextBox1LookIn:=xlFormulasLookAt:=xlPart)
    If 
    Not C Is Nothing Then
      Set C 
    Intersect(C.EntireColumntbl.Range)
      [
    r2:r3] = Application.Transpose(Array(Empty, _
        
    "=IsNumber(Search(" TextBox1 ", " C(2).Address(00, , True) & "))"))
      
    C.AdvancedFilter 1, [r2:r3], , False: [r2:r3].ClearContents
    End 
    If
    End Sub

    Sub clearFilter
    ()
      
    tbl.Range.AutoFilter
    End Sub 
    Of course: the displayed VBA code must go in the sheet module.
    .
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  3. #3
    Registered User
    Join Date
    10-12-2019
    Location
    USA
    MS-Off Ver
    360
    Posts
    48

    Re: Filter Range

    Hello,
    Your guess is correct. Code works only if numeric search. I also like to search for string value. Can you modify the code so I can filter by first, last name and dept.
    Include is an attached sample.

    Thanks
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Filter Range

    For example like this:
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-12-2019
    Location
    USA
    MS-Off Ver
    360
    Posts
    48

    Re: Filter Range

    Hello Mr beyond,

    I did some testing today and code work nicely. I added an extra column for Dates and try to search but no results.
    I used the IsDate in your code but is giving me an error. I see you check for a number using the IsNumber that I requested earlier.
    So how can you also check for dates and then filter the date column. I was thinking of using a different sheet just for searching.
    This way I can print the results for multiple pages. Any idea how to filter by dates in your demo.


    Thanks for your help.

  6. #6
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Filter Range

    .
    While I'm thinking about how to do it, don't forget to 'click' the * at the bottom-left of post #4.

  7. #7
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Filter Range

    When searching for dates, will you be looking for a specific date or a range of dates?

  8. #8
    Registered User
    Join Date
    10-12-2019
    Location
    USA
    MS-Off Ver
    360
    Posts
    48

    Re: Filter Range

    Good morning Mr Beyond

    I would like to search for a range of dates. I added a * for post #4 and put a nice comment.

    Thanks

  9. #9
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Filter Range

    Hello. Analyze this new data configuration:

    PHP Code: 
    Option Explicit
    Dim tbl 
    As ListObject

    Sub applyFilter
    ()
      
    ListObjects("EmpList3").Range.AdvancedFilter 1, [c1].CurrentRegion.Rows("1:2"), , False
    End Sub

    Sub clearFilter
    ()
      
    ListObjects("EmpList3").Range.AutoFilterActiveCell.Activate
    End Sub 
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    10-12-2019
    Location
    USA
    MS-Off Ver
    360
    Posts
    48

    Re: Filter Range

    Perfect, Thanks beyond excel.

    Thank you very much.

+ 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. [SOLVED] Advanced Filter Code : Criteria Range More Than 1 Row Breaks Filter
    By PaulGW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-10-2021, 04:30 PM
  2. Filter range, copy range (not entire column), paste in another worksheet
    By LukeNZ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-21-2018, 08:28 AM
  3. Filter doesn't filter range?
    By RustyNail in forum Excel General
    Replies: 3
    Last Post: 02-27-2018, 01:51 AM
  4. VBA Advanced Filter - Two Filters Without Deleting Bottom Filter Data In Same Column Range
    By hysterical.useless in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2017, 02:54 PM
  5. I Filter range A9:AG300 using listbox(userform) hide all from range blank cells
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2014, 03:28 AM
  6. Filter several pivot tables by one programmed date range filter in Excel 2003
    By olewka in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2011, 11:49 AM
  7. Filter Macro (range contained in filter value)
    By antman10 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-28-2010, 11:09 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