+ Reply to Thread
Results 1 to 5 of 5

Search and filter

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-08-2008
    Location
    Belfast
    Posts
    112

    Search and filter

    Apologies if this is posted in the wrong section, I have a feeling though that I will need a Macro to achieve what I'm after.

    I have a sheet (example attached) that is populated several times a week. At present I mainly use it but it will also be used by all staff to find relevant notices.

    I need to be able

    At the minute as you can see there are filters in place and a rudimentary search facility. However constantly having to explain why it's required to have to select the topic "Departments" "Title" etc typing in the search criteria, clicking out of the search box then clicking on "search" is becoming a RPITA.

    Is there a way to just search the sheet for any given criteria by typing it in a search box and hitting search (not having to highlight a particular column or have to click out etc first)?

    Hope I'm making sense.

    As usual all help greatly appreciated.
    Attached Files Attached Files
    Last edited by Davycc; 07-21-2015 at 08:39 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    856

    Re: Search and filter

    Not Sure if you can do that with a textbox/shape object.

    But you can do this by entering your search criteria into a Cell/Range and using a WorkSheet_Change event like this.

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim sht As Worksheet
        Dim DataRange As Range, rngToLook As Range
        Dim myButton As OptionButton
        Dim SearchString As String, ButtonName As String
        Dim myField As Long
    
        Set rngToLook = Intersect(Target, Range("D2"))
        If Not rngToLook Is Nothing Then
            'Unfilter Data (if necessary)
            On Error Resume Next
            ActiveSheet.ShowAllData
            On Error GoTo 0
      
            'Filtered Data Range
            Set DataRange = Range("A4:E31")
    
            'Retrieve User's Search Input
            mySearch = rngToLook
       
            'Determine if user is searching for number or text
            If IsNumeric(mySearch) = True Then
                SearchString = "=" & mySearch
            Else
                SearchString = "=*" & mySearch & "*"
            End If
        
            'Loop Through Option Buttons
            For Each myButton In ActiveSheet.OptionButtons
                If myButton.Value = 1 Then
                    ButtonName = myButton.Text
                    Exit For
                End If
            Next myButton
       
            'Determine Filter Field
            myField = WorksheetFunction.Match(ButtonName, DataRange.Rows(1), 0)
       
            'Filter Data
            DataRange.AutoFilter _
                Field:=myField, _
                Criteria1:=SearchString, _
            Operator:=xlAnd
        End If
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-08-2008
    Location
    Belfast
    Posts
    112

    Re: Search and filter

    If you read my pre edited post ignore it. I just saw the ammended sheet. I was just going by your code.

    DUH

    I am a pratt.

    Can there be a refresh or similar button to return to showing all entries.

    Once again many thanks for this it really is just what I'm looking for. I appreciate it, there looks like quite some work in your code.
    Last edited by Davycc; 07-21-2015 at 09:43 AM. Reason: Thread starters stupidity

  4. #4
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    856

    Re: Search and filter

    You could put this in a normal module

    Sub ShowAllData()
        On Error Resume Next
        ActiveSheet.ShowAllData
    End Sub
    See the attached.

  5. #5
    Forum Contributor
    Join Date
    08-08-2008
    Location
    Belfast
    Posts
    112

    Re: Search and filter

    Perfect, just what I need.

    many thanks

+ 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. Replies: 4
    Last Post: 11-08-2014, 04:57 AM
  2. Replies: 2
    Last Post: 10-07-2013, 04:57 AM
  3. [SOLVED] Macro/s to create Search Bar to filter to search terms entered activated by Command Button
    By JasonRay in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-08-2013, 03:44 PM
  4. Filter/Search help
    By RobJon73 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-05-2013, 06:52 AM
  5. search for a name and then filter on it
    By Migraine in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2009, 02:28 PM
  6. Great Combo Filter/Search form, cant get DATE filter to integrate. HELP
    By fau5tu5 in forum Access Programming / VBA / Macros
    Replies: 4
    Last Post: 05-18-2009, 05:05 PM
  7. Advance filter search does not filter an exact match
    By cfiiland in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2005, 08:05 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