Consulting

Results 1 to 6 of 6

Thread: Auto Filter problem

  1. #1
    VBAX Newbie
    Joined
    Dec 2004
    Posts
    3
    Location

    Auto Filter problem

    Hi
    I want to use the value that is input into textbox1 to filter on.
    It should filter all the data that contains the value in the textbox.
    I wrote a macro to record the contains filter and was given this:

    Selection.AutoFilter Field:=1, Criteria1:="=**", Operator:=xlAnd

    I have tried to modify it but cannot get the conatins part to work

    The code below I thought would work but the filter type is "ends with" rather than contains. The value is picked up correctly from textbox1.

    Selection.AutoFilter Field:=1, Criteria1:="=**" & TextBox1.Value, Operator:=xlAnd


    Any Advice?

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi scott, welcome to the board!


    Do you think you could post your entire code, along with a zipped example of your workbok? And don't forget to check out the VBA tags when posting (created by our own Mark007!) that make your code look very good!

  3. #3
    VBAX Newbie
    Joined
    Dec 2004
    Posts
    3
    Location

    Unhappy

    The file is real big but I can make a small version.

    Ok done it. real basic but demonstartes my problem.
    In collumn A there are numbers written one, two, three, etc

    If you click on the button it brings up a user form that if you type in the letter E and run I want to to filter on all data in collumn A that contains the letter E.

    I have tried numerous variations to the code but have no joy.
    This code takes the letter from the textbox in the user form but filters it as "ends with".

    Hope you can help Ive been after a solution all day!

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Just add the second asteriks after the value ...

    Criteria1:="=*" & TextBox1.Value & "*"
    So your routine might look something like this ...


    Private Sub CommandButton1_Click()
        Range("A1").AutoFilter Field:=1, Criteria1:="=*" & TextBox1.Value & "*", Operator:=xlAnd
        UserForm1.Hide
    End Sub
    (No need to select ..)

  5. #5
    VBAX Newbie
    Joined
    Dec 2004
    Posts
    3
    Location

    Thumbs up

    Many thanks for that!

    I thought I tried all combinations with the *, =, & textbox1 but obviously not.

    Frustration over with!

    Thanks Again

    Scott

  6. #6
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Scott,

    Just an FYI, I've changed your thread from "Closed" to "Solved". This will still let someone post to it, just in case they have a gem they want to share, and also marks it so that others know you're A-Okay!

    If you still think it should be "Closed" (to prevent others from posting to it), by all means go ahead though!

    Cheers,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •