+ Reply to Thread
Results 1 to 3 of 3

Using collection for autofiltering

  1. #1
    Registered User
    Join Date
    08-27-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    2

    Using collection for autofiltering

    Hi guys

    I have generated a list of unique values in a Collection that I'm now unsuccessfully trying to use as AutoFilter Criterias. Anyone knows how to do this?

    I have generated the list like this (only the relevant part :-)):

    Dim myRow As Integer
    Dim myRange As Range
    Dim myCount As Integer

    Range("B1").Select
    Selection.End(xlDown).Select
    myRow = ActiveCell.Row
    Set myRange = Range("B2:B" & myRow)
    myCount = myRange.Count


    Dim myCol As New Collection
    Dim myItem
    Dim i As Long
    Dim myCellVal As Variant

    For i = 1 To myCount
    myCellVal = Range("B" & i + 1).Value
    On Error Resume Next
    myCol.Add myCellVal, Chr(34) & myCellVal & Chr(34)
    On Error GoTo 0
    Next i

    And am now trying to apply the filter like this:

    ActiveSheet.Range("$A$1").AutoFilter Field:=25, Criteria1:=???

    I have tried to use myItem, myCol and myCellVal (both as is and with an (i), e.g. myItem(i), replacing the ??? above.

    Anyone who knows what I'm doing wrong :-)?

    Thanks

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Using collection for autofiltering

    I don't know how to use a collection, but I do know how to use an array created from a collection:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    08-27-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    2

    Re: Using collection for autofiltering

    Thanks a lot :-)!

    Got it to work basically just by replacing my script with yours, only adding a few adjustments (needed the autofilter applied in a different sheet) so it was just perfect :-).

+ 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] Performance of iteration through Words collection degrades as collection gets bigger
    By 6StringJazzer in forum Word Programming / VBA / Macros
    Replies: 7
    Last Post: 01-14-2014, 09:44 AM
  2. Replies: 2
    Last Post: 12-23-2011, 11:04 AM
  3. Problems storing a Collection within a Collection. Is this possible?
    By Tarball in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2007, 10:47 PM
  4. Autofiltering
    By [email protected] in forum Excel General
    Replies: 2
    Last Post: 10-04-2005, 10:05 AM
  5. Sum & autofiltering
    By Edward Cheung in forum Excel General
    Replies: 1
    Last Post: 01-04-2005, 01:46 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