+ Reply to Thread
Results 1 to 17 of 17

Complex filtering of a table

  1. #1
    Registered User
    Join Date
    10-19-2020
    Location
    Bristol, England
    MS-Off Ver
    365 (& 2013)
    Posts
    85

    Complex filtering of a table

    I need to filter a table but I need to do that based on the values in several cells, not a simple "=red" or ">1".


    The basic rule I need will contol 3 cells...

    If InvDate & InvNo are not blank but PaidDate is blank then Dont hide

    But this needs to account for multiple groups of the 3 cells (as columns) & multiple rows


    It could filter Columns first in the groups of 3 then the rows to clear out unwanted columns & then rows in 2 passes?


    I've attached a proxy file to try to explain what I need to do. I would give you my attempts at code but I'm not sure where to start.

    The real version has 30 groups of 3 columns & thousands of rows, so I figure filter will be the best solution due to speed (feel free to tell me I'm wrong & why).
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,409

    Re: Complex filtering of a table

    Please Login or Register  to view this content.
    Output on Sheet1
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

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

    Re: Complex filtering of a table

    To Sheet4 code module.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    10-19-2020
    Location
    Bristol, England
    MS-Off Ver
    365 (& 2013)
    Posts
    85

    Re: Complex filtering of a table

    Thankyou to both of you for taking the time to make a working example.

    I'm off to play with your code to understand how it works as I can't immediately follow either solution (but will be unpicking both of them over the next few hours).

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,409

    Re: Complex filtering of a table

    Thank you for the rep and please come back if you need further help.

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

    Re: Complex filtering of a table

    CMOT Dibbler,
    You are welcome and thanks for the rep.

    You would notice that they work differently, so I have posted my solution.

  7. #7
    Registered User
    Join Date
    10-19-2020
    Location
    Bristol, England
    MS-Off Ver
    365 (& 2013)
    Posts
    85

    Re: Complex filtering of a table

    Please can I ask a few quick questions

    I apologise if any of this is a bit obvious, I’ve tried to google what I couldn’t understand & have shortened my questions by quite a bit, but these I couldn’t resolve...



    With Me.ListObjects(1)

    Why didn't you use the table name? is there a specific reason?


    If (a(i, ii) <> "") * (a(i, ii + 1) <> "") * (a(i, ii + 2) = "") Then

    You're using * where I would have used and. Again is there a specific reason?


    dic(0)(CStr(.ListRows(i - 1).Range(1).Value)) = Empty: flg = True

    I'm a bit I'm confused by Range(1), where has that come from? I'm sure it's the current group of 3 columns, but I wondered how it knew what it was.


    If dic(0).Count Then

    what is it doing here? I can see it's an if to trigger removing the rows, But in the example it's storing 4, (It appears to be the number of rows to keep?) what is the if comparing that 4 against?


    .Range.AutoFilter 1, dic(0).keys, 7

    I can see its autofiltering using the keys in the Rows Dictionary, but what's the 7?
    Last edited by AliGW; 04-11-2024 at 05:50 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

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

    Re: Complex filtering of a table

    1) You can change it to table name, if you like.
    2) Again, you can change "*" to "And", if you like.
    3) ListRows(1).Range(1) refers to First column in first data row. Range(2) = second column..etc.
    Unlike Range on the worksheet, Range on the ListObject works differently.
    4) dic(0) is storing the Col.A value that should be filtered (should remain).
    So, when no data in dic(0), no need to filter the rows.
    5) 7 is the constant for xlFilterValues.

    HTH.

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

    Re: Complex filtering of a table

    I noticed a contradiction for 4)...
    If dic(0).Count = 0, no data to be filtered (all rows need to be hidden), so the code should look like.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-19-2020
    Location
    Bristol, England
    MS-Off Ver
    365 (& 2013)
    Posts
    85

    Re: Complex filtering of a table

    The additional answers have helped a lot. Today has been another leveling up day

    Thanks again for taking the time to help.
    Last edited by AliGW; 04-11-2024 at 05:49 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  11. #11
    Registered User
    Join Date
    10-19-2020
    Location
    Bristol, England
    MS-Off Ver
    365 (& 2013)
    Posts
    85

    Re: Complex filtering of a table

    Quote Originally Posted by JohnTopley View Post
    Thank you for the rep and please come back if you need further help.
    Thanks again for taking the time to post your code. It was very appreciated.

    I've gone through your code after I went through jindon's code & yours obviously works in a very similar way but without using the dictionary.

    The copying to sheet 1 is a very useful & timely addition. I need to filter the data & copy it to another sheet in the real worksheet, so that was an inclusion which will definitely get used.

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

    Re: Complex filtering of a table

    The main difference is to hide columns like your example...

  13. #13
    Registered User
    Join Date
    10-19-2020
    Location
    Bristol, England
    MS-Off Ver
    365 (& 2013)
    Posts
    85

    Re: Complex filtering of a table

    I've hit a snag.

    Even if I preclean the table to reduce the number of rows required I'm getting an error.

    a = .Range.Value

    It's erroring with Run-time error 6 Overflow

    The live table is currently at 84 columns & 1000 rows when cleaned.

    Is there a way out of this? Or do I have to use another methodology?

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,711

    Re: Complex filtering of a table

    You might want to remove the SOLVED tag for now, then.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,300

    Re: Complex filtering of a table

    Most likely you have some cells that are formatted improperly (they probably appear as ###### in the worksheet). Try using:

    Please Login or Register  to view this content.
    Anyone who confuses correlation and causation ends up dead.

  16. #16
    Registered User
    Join Date
    10-19-2020
    Location
    Bristol, England
    MS-Off Ver
    365 (& 2013)
    Posts
    85

    Re: Complex filtering of a table

    Quote Originally Posted by rorya View Post
    Most likely you have some cells that are formatted improperly (they probably appear as ###### in the worksheet). Try using:

    Please Login or Register  to view this content.
    Thanks for taking the time to post.

    I can't get to it at the moment, but I'll try changing the code tomorrow & report back.

    All calculations are done in the forms & the main table is just a repository, so I don't think that's the case.

    The cells all contain stings copied & Pasted in from the main table (so no formula), but there may be some special char hiding in a "blank" cell. I've had that issue before.

  17. #17
    Registered User
    Join Date
    10-19-2020
    Location
    Bristol, England
    MS-Off Ver
    365 (& 2013)
    Posts
    85

    Re: Complex filtering of a table

    Sorry for the delay in posting, the role I was hired to do took over for a while

    It's now all working & it was dirty cells causing the issue, so thanks to rorya for the hint that got me to look in the right direction.

    If anyone is struggling with a similar issue rollis13 helped out a while ago with the code to clean up any "blank" but dirty cells & thats how I got it to work. that code is here...

    https://www.excelforum.com/excel-pro...ank-cells.html

+ 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. Complex Checkbox Filtering
    By yggdrasilsyeoman in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-21-2022, 07:58 PM
  2. Advance/Complex Table pivot or filtering need
    By arctushar in forum Excel General
    Replies: 3
    Last Post: 08-30-2014, 08:44 PM
  3. [SOLVED] Complex Filtering & Copying With VBA (Need Help)
    By Nctukek in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 04-15-2014, 12:15 PM
  4. [SOLVED] Sorting and filtering complex data (with a pivot table)
    By Durarara in forum Excel Charting & Pivots
    Replies: 15
    Last Post: 10-03-2012, 02:36 AM
  5. Complex filtering/sorting
    By baniels in forum Excel General
    Replies: 0
    Last Post: 06-17-2009, 11:49 AM
  6. Complex Filtering
    By sheetalkamat in forum Excel General
    Replies: 0
    Last Post: 05-19-2005, 10:52 AM
  7. Excel complex filtering question
    By grphillips in forum Excel General
    Replies: 0
    Last Post: 02-02-2005, 10:33 AM

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