+ Reply to Thread
Results 1 to 3 of 3

Macro to display rows from another tab, based on 2 criteria (List and keyword)

Hybrid View

KenzoMinamoto Macro to display rows from... 06-24-2013, 12:45 AM
AlphaFrog Re: Macro to display rows... 06-24-2013, 02:40 AM
KenzoMinamoto Re: Macro to display rows... 06-25-2013, 09:17 PM
  1. #1
    Registered User
    Join Date
    06-23-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    2

    Macro to display rows from another tab, based on 2 criteria (List and keyword)

    Hello,

    Firstly, thank you all for your help in the past, I'm a long time lurker, first time poster.
    Very impressed with the macros and answers on this forum. All of my past attempts are crude and simple (done via recording), but it gets the job done.
    Unfortunately I am unable to solve my current dilemma with my limited knowledge on macros.

    I am trying to get my buying guide spreadsheet to display all rows based on 2 criteria; the first is a keyword search and the second is from a drop down list of Australian states.
    The keyword search is based on a product or service, and could be something like "enviro* assess*". On my data tab, i have described these services based on the vendor's capabilities, on the data tab in Column P.
    The drop down list contains a list of Australian states, the data validation is in the Lists tab, and corresponds to the column A in the data tab.
    Please see my sample file as attached.

    I found an elegant macro in the below page and have tried to amend it to suit my needs, to no avail.
    http://www.excelforum.com/excel-prog...filtering.html

    I would greatly appreciate if someone could help modify this macro with the following changes
    1. Instead of having a popup, could this please be changed to analysing the data based on the information in the Results tab, cells F3 and I3.
    2. the search to be done first on the State, then by keyword (in the example on the attached file, search by VIC in Data! Column A, then for anything with enviro* in Data! column P
    3. display all rows in the Results tab, from row 6 onwards

    I would greatly appreciate if I could just type in a keyword (with or without wildcard), select a state, then click on the button to display all of the vendors from my data tab, who are capable of performing the requested service in the relevant state.

    Many thanks in advance!!
    KenzoBuying guide test.xlsm

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Macro to display rows from another tab, based on 2 criteria (List and keyword)

    Buying guide test.xlsm

    Sub FindKeywords()
    
        Dim wsData As Worksheet
        
        Set wsData = Sheets("Data")
        
        With Sheets("Results")
        
            If IsEmpty(.Range("F3")) Then
                MsgBox "Missing keyword in cell F3 ", vbExclamation, "Invalid Keyword Entry"
                Exit Sub
            ElseIf IsEmpty(.Range("I3")) Then
                MsgBox "Please select a state in cell I3 ", vbExclamation, "Missing State Entry"
                Exit Sub
            End If
            
            Application.ScreenUpdating = False
            
            'Filter data
            wsData.AutoFilterMode = False
            wsData.UsedRange.AutoFilter Field:=16, Criteria1:="*" & .Range("F3").Value & "*"
            wsData.UsedRange.AutoFilter Field:=1, Criteria1:=.Range("I3").Value
            
            If wsData.Range("A" & Rows.Count).End(xlUp).Row = 1 Then
                MsgBox "No data matches the filter critera. ", vbInformation, "No Data Match"
            Else
                'Clear previous data match
                If .Range("A" & Rows.Count).End(xlUp).Row > 5 Then
                    .Rows("6:" & .Range("A" & Rows.Count).End(xlUp).Row).ClearContents
                End If
                'Copy filtered data
                wsData.AutoFilter.Range.Offset(1).Copy Destination:=.Range("A6")
            End If
            
            wsData.AutoFilterMode = False
            Application.ScreenUpdating = True
            
        End With
            
    End Sub

  3. #3
    Registered User
    Join Date
    06-23-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro to display rows from another tab, based on 2 criteria (List and keyword)

    Hello AlphaFrog,

    Thank you very much for this!
    It's brilliantly done, much appreciated!

    K

+ 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