+ Reply to Thread
Results 1 to 5 of 5

Filtering in VBA

  1. #1
    Registered User
    Join Date
    10-04-2012
    Location
    Aguascalientes
    MS-Off Ver
    Excel 2003
    Posts
    3

    Filtering in VBA

    I need to be able to filter a list (which I get from an external database) with many filters. The list has in one colum a product code (about 5000 different ones) that repeats as many sales as each salesman made and I need to know who sold what so I made a macro that worked and looked it up in vba but I have a limit on a consult table cause I don't know how to make a string for tha array that will take only the values of the consulting items.

    I speak spanish, sorry if I didn't explain myself very well.

    so greatful for your help

    Luis
    Please Login or Register  to view this content.
    Last edited by Paul; 10-05-2012 at 12:53 PM. Reason: Added CODE tags for new user. Please do so yourself in the future.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Filtering in VBA

    Hi, Luis,

    according to what I read from your post you might find a Pivot Table a very good solution to your problem without programming - have you already tried to use one?

    If this isnīt what you are looking for and you need further helpplease attach a small sample file with some data and the way you want the data to be placed (and where).

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    10-04-2012
    Location
    Aguascalientes
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Filtering in VBA

    Thanks a lot for your answer. The thing is that I have to do many things after filtering that will require programming so I choose Vba for that reason.
    I now loaded a string but it doesn't recognize it . I know I'm making a silly mistake for not knowing vba but, funny, I can't find the error anywhere at the net.

    show you my last try.
    Sub Filtrar5()
    Dim Str(0 To 40) As String
    Dim i As Integer


    Str(5) = Worksheets("Busqueda").Cells(5, 1).Value
    For i = 6 To 8
    Str(i) = Str(i - 1) & Chr(34) & "," & Chr(34) & Worksheets("Busqueda").Cells(i, 1).Value
    Next

    ActiveSheet.ListObjects("Tabla_MOV001PRIMERA").Range.AutoFilter Field:=1, _
    Criteria1:=Array(Str()), Operator:=7
    End Sub

    the string Str() loads fine but it doesn't reply the result under the array().

    Thanks Holger for all your help!

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Filtering in VBA

    Hi, Luis,

    you are using an Array with 41 items but only fill the items 5 to 8. If you fill an item in an array I would pass on unique values to eqch and any item and put them together right before the use in the Autofilter.

    I built a small example and ran yoour macro for an output into the direct window which looked like this:
    Please Login or Register  to view this content.
    To me it seems there are some " missing at the very start and at the end of the strings.

    Please try this different approach:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    10-04-2012
    Location
    Aguascalientes
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Filtering in VBA

    came out working all right! thanks a lot for all your help
    regards, Luis

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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