Maximising use of AutoFilter


  • I am using the above to identify patient results that I wish to follow up. My question is whether there is a way to select records based either on Field4 or Field3 OR field5 or field6 etc? The above syntax seems to imply criterion1 AND criterion2 and so on.
    Much obliged

  • Re: Maximising use of AutoFilter


    Hi Ian


    By having a line for each field, that should work as the 'or' operator. The 'xlOr' operator in your code applies to the criteria, not the field.

  • Re: Maximising use of AutoFilter


    When I apply the above macro , it selects only the records that fulfil all of the criteria, whereas I want the records that fulfil any of the criteria. I hope that this makes sense

  • Re: Maximising use of AutoFilter


    Apologies, I misunderstood.


    You will either have to use Advanced Filter or a slightly more involved macro with autofilter. Does it have to be filtered in place or can it be copied to another sheet? Can it only be through a macro?

  • Re: Maximising use of AutoFilter


    Something to play around with (not tested):


  • Re: Maximising use of AutoFilter


    Thank you. This seems to work perfectly. I shall 'play' around with it with a real data sheet. Brilliant!

  • Re: Maximising use of AutoFilter


    Hi again. Something weird happens when I use the macro on the "real" thing: although the real data have exactly the same format as the dummytrial and the macro works perfectly with the dummyfile even when I copy the "real" data to it.
    When I use the macro as it is written, I get the message Compile error: Expected End Sub. When I add End Sub below the last End If, I get a compile error: Only comments may appear after End Sub, End Function, or End Property.
    What have I done or what do I need to do? THanks

  • Re: Maximising use of AutoFilter


    Problem solved! I deleted all modules from the macros that I use for this spreadsheet which is initially received as a csv file. I then reloaded the module for identifying and reporting the results and it now works perfectly. Iguess that I must have had more than one module that conflicted.
    A last question on this topic. Is it possible to transfer the results to appear in a formatted way , similar to the message box in appearance, but with formatted text ?

  • Re: Maximising use of AutoFilter


    Glad you sorted it. I am not quite sure what you mean by the last question. You can do some formatting with a message box. Or maybe use a userform.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!