+ Reply to Thread
Results 1 to 4 of 4

Using a macro to operate a filter on variable data

  1. #1
    Registered User
    Join Date
    02-28-2014
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    Question Using a macro to operate a filter on variable data

    Hi,

    I have a written a macro to populate a filter criteria with a comma separated list, but the filter fails to work as each individual item on the list needs to be surrounded by speech marks (") and I don't know how to do this.

    This may not be an actual vba issue?

    The list I am using is derived from =SUBSTITUTE(TRIM(BK9&" "&BK15&" "&BK21)," ",",") There are 120 different cells that this formula references that could be blank. The SUBSTITUTE TRIM functions allow me to just use the cells that have data in. But I can't seem to get the " symbols in there. (I've tried the TEXT function on the original cells, & this doesn't work.


    Any ideas?

    Thanks

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Using a macro to operate a filter on variable data

    try:
    ="""" & SUBSTITUTE(TRIM(BK9&" "&BK15&" "&BK21)," ",""",""") & """"
    (outside 4somes and around comma 3somes of speechmarks)
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    02-28-2014
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Using a macro to operate a filter on variable data

    Thanks Kaper. This worked, but the macro didn't .

    I'll try & explain what I'm trying to do as I cannot attach a mini workbook due to the complexity of the document I am working on (I can't simplify it enough):

    I am trying to replicate the array on an Excel Autofilter as part of a macro. Below is a sample of the filter array:


    ActiveSheet.Range("$A$60:$ACQ$6356").AutoFilter Field:=1, Criteria1:=Array( _
    "01103032", "01103033", "01103034", "01103035"), Operator:=xlFilterValues

    There are 4 items in the array shown, but I would want to filter up to 120 items. I've tried to replicate the array as a string called 'skurange' as you can see below:

    ActiveSheet.Range("$A$60:$ACQ$6356").AutoFilter Field:=1, Criteria1:=Array( _
    "" & skurange & ""), Operator:= _
    xlFilterValues

    This doesn't seem to work however as the filter returns no data.( I had already spotted that there is a space betwen the comma and the speechmarks & corrected this in the substitute function)

    Any ideas?

    Thanks in advance.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Using a macro to operate a filter on variable data

    An array is an array :-)

    try:
    Please Login or Register  to view this content.
    then try another array (if skurange contains for instance string with values separated by space):
    Please Login or Register  to view this content.
    hope it shows the way.

    PS. if you want to add one by one elements to an array, get familiar with
    Please Login or Register  to view this content.

+ 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] Re: How to set logic for a macro tool that will import , operate and save the reports.
    By VKR in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2013, 03:41 PM
  2. Needing to operate pivot table with check boxes instead of report filter.
    By jaimeteele in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-22-2013, 01:51 PM
  3. [SOLVED] user variable macro filter thing
    By ashfire in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2006, 09:55 AM
  4. Macro to operate remote form
    By MikeP in forum Excel General
    Replies: 0
    Last Post: 11-28-2005, 06:30 PM
  5. Replies: 5
    Last Post: 02-28-2005, 01:06 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