Consulting

Results 1 to 11 of 11

Thread: Modify VBA code for Advanced Filtering

  1. #1
    VBAX Regular
    Joined
    Jan 2017
    Posts
    8
    Location

    Modify VBA code for Advanced Filtering

    Hi everyone, I'm new member here, hope to help me in this.
    Kindly see attachment file which has VBA Code

    What this code is doing?:
    Filtering rows (records) based on two things,
    1- the first letter or letters entered in cell H1
    2- column's(field's) number entered in cell G2
    ---------------------------------------------------------------------------------------------------------------------------------
    What I want ?:
    Ignore enter the Column(field) number in the cell G2 and modify the code to be clever code which can capable to selecting the appropriate Column(field) for filtering_
    by reading the letters entered in cell H1 and compare it with the contents of all columns (fields),_
    and then selects all the rows(records) which it applies input in H1 regardless of the column.
    Thanks for All
    Attached Files Attached Files

  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    Unless I have misunderstood what you are trying to do, I don't think you can do what you want just using the EXcel filter unless you create an extra column to filter on, This is because filtering in Excel is always an "AND" function with multiple columns, there isn't anyway to do an "OR" function without creating an extra column. Your requirement needs the "OR" function"
    So what I would do is run a macro to search each column for the string, if it is present put "TRUE" in the extra column, then after running the macor you just filter on that column.

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    What is your goal ? Why filtering on letters ? (for gender e.g.)

  4. #4
    VBAX Regular
    Joined
    Jan 2017
    Posts
    8
    Location

    Thumbs up thanks for replying

    I think you have good logical thinking, you are right. you give me nice ideai, ill try it. thanks a gain.

    Quote Originally Posted by offthelip View Post
    Unless I have misunderstood what you are trying to do, I don't think you can do what you want just using the EXcel filter unless you create an extra column to filter on, This is because filtering in Excel is always an "AND" function with multiple columns, there isn't anyway to do an "OR" function without creating an extra column. Your requirement needs the "OR" function"
    So what I would do is run a macro to search each column for the string, if it is present put "TRUE" in the extra column, then after running the macor you just filter on that column.

  5. #5
    VBAX Regular
    Joined
    Jan 2017
    Posts
    8
    Location
    thanks for replying, the file which I attached was just sample. of course there is logical reason to filtering on letters. thanks a gain.
    Quote Originally Posted by snb View Post
    What is your goal ? Why filtering on letters ? (for gender e.g.)

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Try the attached.
    Delete H1 contents to restore the full unfiltered list.

    What you had in your file wasn't Advanced Filter, it was automation of Autofilter.
    Whereas what is in the attached IS Advanced Filter, automated.
    The criteria range is P1 to P6 but it can be squirrelled away anywhere after tweaking the code.
    P4 contains a slightly different formula because column C (Age) is numeric. You might want to tweak that formula.
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  7. #7
    VBAX Regular
    Joined
    Jan 2017
    Posts
    8
    Location

    New File with my solution.

    today I'll upload new file with my solution.

    Quote Originally Posted by Younes View Post
    thanks for replying, the file which I attached was just sample. of course there is logical reason to filtering on letters. thanks a gain.

  8. #8
    VBAX Regular
    Joined
    Jan 2017
    Posts
    8
    Location
    today I'll upload new file with my solution.

  9. #9
    VBAX Regular
    Joined
    Jan 2017
    Posts
    8
    Location

    I found a solution.

    Hi
    I find a solution for filter a table without select any column, just enter any letter/s or number you see in any cell in table to filtering. hope its useful.
    Thanks
    Attached Files Attached Files

  10. #10
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Please do not Quote !

  11. #11
    VBAX Regular
    Joined
    Jan 2017
    Posts
    8
    Location
    Thanks a lot. good works

Tags for this Thread

Posting Permissions

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