Consulting

Results 1 to 8 of 8

Thread: Autofilter custom shortcut

  1. #1

    Unhappy Autofilter custom shortcut

    I am using a spreadsheet that has 3 columns and about 2000 rows. I only filter column A1 (Products) and I use the autofilter > custom... 'begins with' and then I type part of my product code to find what I'm looking for.
    This works well but is time consuming. I tried to create a macro to open the 'custom' dialouge box but it records the whole search which is no good for my problem.
    I thought that I could create a button that acts as a shortcut to open the Autofilter Custom dialogue box but I have had no luck.
    Would it be better for me to create my own form with a text field and search button?
    Can somebody give me some advise please?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Here is one way.

    You put the begin string in a cell and the filetr code picks that up

    [vba]

    Sub FilterData()
    Const WS_CRITERIA_CELL As String = "D1" '<=== change to suit

    With ActiveSheet

    .Columns("F:F").AutoFilter Field:=1, _
    Criteria1:="=" & .Range(WS_CRITERIA_CELL).Value & "*"
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    That's gone right over my head.

    Hi XLD,

    Sorry I'm a new to this, can you break it down for me?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    in what way? How to install it, or what it does?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5

    Both

    Both?

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    OK.

    To install it, just add the code to a standard code module.

    Then just add a button from the Forms toolbar, and assign that macro to it.

    What the code does is to to add an Autofilter and to filter using a criteria of begins with the text that is in cell D1. The code assumes that the data to be filtered is in coolumn F, just change those two things to your situation.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Bob, John has a wink that shows how to get to the vbe. Once there poster can go to insert-module to insert a standard module.

    http://xlvba.3.forumer.com/index.php?showtopic=361

    This is for beginners..
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8

    It works!

    XLD, thanks a lot it works a treat. This is going to make my life much easier. Thanks again.

    Jay

Posting Permissions

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