+ Reply to Thread
Results 1 to 8 of 8

VBA - AutoFilter an array containing wildcards?

  1. #1
    Registered User
    Join Date
    08-02-2012
    Location
    Europe
    MS-Off Ver
    Excel 2013/365
    Posts
    24

    VBA - AutoFilter an array containing wildcards?

    Hi,

    First post, longtime lurker.

    I'm building a report and as part of that I need to collect certain Invoice IDs based on what type of Product Offers IDs they contain. The crux is that the Invoice IDs can contain multiple Product Offer IDs (separated by semicolons) in no particular order in one cell and I only want to collect the invoices containing the specific products I'm after. From what I can tell an Autofilter array doesn't seem to work with wildcards so I'm looking for help.

    I've attached an example .csv containing InvoiceID and OfferList columns. There are 12 invoices with a set of product offers (Item.OFD.50.00001 through Item.OFD.50.00008).

    For the sake of the example I'm looking to collect Invoice IDs 1-7 and 10-12 which contain offers 1, 2, 4, 5, 6, 7 anywhere in them but not invoices 8-9 that only contain offers 3 and 8. In my real report there are hundreds of offers of which I'm looking to collect around 50. The offers I want to collect are always known but the actual total offer IDs in the source files are unknown.

    This is the code part I've made, which only works for Invoices where there is only one product offer per cell, I'm looking to expand this so it suits my outlined example with multiple products per invoice.

    Please Login or Register  to view this content.
    Many thanks for any help.
    Attached Files Attached Files
    Last edited by Tunesmith; 11-03-2014 at 01:18 PM. Reason: Solved

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: VBA - AutoFilter an array containing wildcards?

    Two options are basically either to loop through all the data checking against your desired list, then add those items as literal strings to an array that you can use in the autofilter, or to use an advanced filter instead. The only downside to the advanced filter is that you do need to enter the criteria into cells somewhere. Where are you running the code from, and how do you select the items you are interested in?
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    08-02-2012
    Location
    Europe
    MS-Off Ver
    Excel 2013/365
    Posts
    24

    Re: VBA - AutoFilter an array containing wildcards?

    The code sits in a sub within a .xlam addin. This code piece would be part of a larger sub which first merges together a number of .csv files before running the filter code which presents the result in a new sheet.
    Currently, which products to filter on would be hard-coded in the code, the product offer IDs will very rarely change.

    The "ThisWorkbook" object of the .xlam already have a few named tables in it which are used for vlookups by other macro subs. Adding another named table with a list of the offer IDs to filter would be an option if that would work.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: VBA - AutoFilter an array containing wildcards?

    Yes, that would work - you just need to make sure that the column header in your add-in matches the column header in the data sheet, and that the offer IDs in your add-in are enclosed in * wildcards, then you can use simply:
    Please Login or Register  to view this content.
    for example.

  5. #5
    Registered User
    Join Date
    08-02-2012
    Location
    Europe
    MS-Off Ver
    Excel 2013/365
    Posts
    24

    Re: VBA - AutoFilter an array containing wildcards?

    Got that to work, much appreciated romperstomper. I haven't really used AdvancedFilters previously.

    Just thinking ahead on two points.

    1) I usually convert ranges to named tables in the ThisWorkbook in the .xlam. I name the tables so I don't have to modify a range in the code when I update the tables with the occasional new item. How would I refer to the range if it was defined as a named table in this case? For the sake of example, the addin is named "TheAddin.xlam" and the Table is "TheTableName". For a vlookup formula I'd use this as a value (adjusted as necessary):
    Please Login or Register  to view this content.
    2) If I would want to filter the AdvancedFilter using a secondary criteria as well, how would I do that? With AutoFilters I'd just add a new criteria.
    As example, a third column with "A" and "B" in it and I would filter for the Invoices which were "B" and then the desired Offer IDs. Is there a simple way to do that or do you need to do first an AutoFilter for "B"'s, copy/paste this on a new sheet, and then run the AdvancedFilter?

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: VBA - AutoFilter an array containing wildcards?

    You would refer to:
    Please Login or Register  to view this content.
    For multiple criteria it can get tricky. If it's just one other criterion as in the example you describe, you could just add another column to your table with the relevant column headers and enter "B" into each row.

  7. #7
    Registered User
    Join Date
    08-02-2012
    Location
    Europe
    MS-Off Ver
    Excel 2013/365
    Posts
    24

    Re: VBA - AutoFilter an array containing wildcards?

    Great, that suits my purposes perfectly. Thanks for helping me.

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: VBA - AutoFilter an array containing wildcards?

    Glad to help.

+ 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. Autofilter wildcards Excel 2007 VBA
    By jonas15 in forum Excel General
    Replies: 0
    Last Post: 12-19-2012, 09:00 AM
  2. Autofilter for 3 criteria using wildcards
    By gembrook in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2012, 03:20 AM
  3. AutoFilter Wildcards
    By myers601 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2012, 09:44 AM
  4. Filtering with Wildcards using Autofilter
    By Motox in forum Excel General
    Replies: 2
    Last Post: 03-16-2012, 06:40 AM
  5. Array with two wildcards
    By Watson2 in forum Excel General
    Replies: 3
    Last Post: 06-10-2009, 03:59 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