+ Reply to Thread
Results 1 to 10 of 10

VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

  1. #1
    Registered User
    Join Date
    01-07-2009
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2007
    Posts
    10

    VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    Hi all,

    First, I'd like to thank this forum of basically helping me learn VBA, without any programming experience, and without asking questions. basically the wealth the forum has of existing questions and solutions are enough probably to solve all issues.

    Yet i can's solve this one by myself

    I have "written" a code, that filters a range based on combobox values found in another sheet, then copies the result and does some basic calculations.

    the code is run when clicking a cell (Report in G1):

    This is the code from the Report sheet (stored in a sheet):

    Please Login or Register  to view this content.
    The code works! yet not everytime! sometimes it doesn't apply the filters and copies the whole table. at first this wasnt an issue, as the data were small, but now the data table has expanded to the point that copying the whole data takes a lot of time and make Excel hangs.

    when it doesnt work, I have a Clear results VBA code that clears the pasted table, Clear (Clear , G2), after which i click report again and hope that it works

    The autofilter picks up values from two comboboxes, found in Report sheet, the entries in both combo boxes are entered via two macros, called when the Report sheet is activated (above, in red):

    This is the code for the Report (stored in a module):

    Please Login or Register  to view this content.
    I tried stepping into/debugging the code, when i do that, autofilters work all the time.

    I'd appreciate any help here, using Excel 2007, PC, fully updated.

    Thanks
    Ahmed

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    Try replacing:
    Please Login or Register  to view this content.
    with:
    Please Login or Register  to view this content.
    Last edited by kev_; 05-23-2017 at 07:39 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    or replacing
    Please Login or Register  to view this content.
    with:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-07-2009
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    Hikev_

    thanks for the input.

    I tried both, they didnt work:

    first option (on error resume next) results in the same behavior

    second option (.AutoFilterMode = False) gives an error popup (run-time error 438: object doesn't support property or method)

    do you think the issue is related to auto filter?

    from observation, first time running the report macro (after opening the workbook) always fails. second time will work! that is, without doing anything: aka changing values in the comboboxes or switching sheets, etc.

    do you think thats relevant?

    Ahmed

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    autofiltermode is a property of the sheet not the range AFAIK, so :
    Please Login or Register  to view this content.
    should work, this would go just before you apply the new filter.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  6. #6
    Registered User
    Join Date
    01-07-2009
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    HI Arkadi,

    I added that line to remove autofilter, but that doesnt really solve the issue,. The first time I do the report the whole data is inserted (autofilter is not applied),
    doing the exact thing again, it works perfectly!

    Thanks
    Ahmed

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    any chance you can provide the workbook with sensitive data cleaned out?

  8. #8
    Registered User
    Join Date
    01-07-2009
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    HI,

    attached

    I tried to clean everything, fingers crossed

    PS: all formulas will not work, thats fine

    to reproduce:

    go to Report sheet, click report (it might take a while)

    you will notice it will not take whatever data are there in the combo boxes.

    after its done, click clear or click report again (clear is part of report) and data will be filtered via input from the comboboxes and copied correctly

    PS: some bits in the code are either 'ed or redundant

    Thanks in advance.

    Regards,
    Ahmed
    Attached Files Attached Files

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    I noticed I can make it fail every time by switching to the 2017 sheet and then back again, run the code, it fails, run it again it works, switch sheets, it fails.

    However, by modifying one line (adding specialcells) in the filter/copy code, it seems to work consistently, maybe the filter is too slow in registering, though it clearly works since the specialcells statement would only help if the filter is applied properly:

    Please Login or Register  to view this content.
    EDIT: Forgot to specify.... this is in the FilterAndCopy Subroutine.
    Last edited by Arkadi; 05-23-2017 at 11:35 AM.

  10. #10
    Registered User
    Join Date
    01-07-2009
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA :Inconsistency filtering with autofilter using referenced values from ComboBoxes

    Hi Arkadi,

    Thank you very much! that worked! i have the least idea what specialcells are (will start reading about them).

    thanks for the efforts and time.

    Ahmed

+ 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] Autofilter not filtering
    By jomili in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 04-13-2015, 12:56 PM
  2. Replies: 3
    Last Post: 02-18-2015, 02:02 PM
  3. filtering comboboxes depend on value of other comboboxes
    By hassan khansa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-18-2014, 09:18 AM
  4. [SOLVED] VBA Autofilter -- Not filtering
    By alansidman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-03-2014, 05:42 PM
  5. Looking for Alternative Ideas for my Situation... dynamically filtering comboboxes?
    By DamnRock in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2013, 04:04 AM
  6. [SOLVED] Calculating Time in Userform Textbox and Filtering Comboboxes Coding Help
    By hiddenupnorth in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-01-2012, 01:12 PM
  7. Filtering with three comboboxes
    By Renovacio in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-28-2008, 01:30 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