+ Reply to Thread
Results 1 to 3 of 3

Filter data w.r.t. different search input

  1. #1
    Registered User
    Join Date
    11-26-2018
    Location
    india
    MS-Off Ver
    2007
    Posts
    22

    Filter data w.r.t. different search input

    Hello,
    I have one excel file in which 40000+ data is present. All data is clutter. attached is one of the example.
    To refine the data I want to filter the data like below.
    In first search box I will put some text e.g. "cough" When I will click it's command button, it will search whole sheet where cough word is present & will show me only the rows which contains "cough" word. Then if needed I will highlight that rows manually.
    Then in next search box I will put another word & when I click it's command button it will search the sheet for that text & show me the only rows which contains that text. Then if needed I will highlight that rows manually.
    Same I will do for next search3, search4 & so on.
    So when I click small command button which is exactly in front of the each search column it will search that specific text only. But when I click the "command button2" (big button below all the small buttons)then it will search the rows where all that words present in search1, search2, search3, search4, likewise are present & will show the only rows which contains all that text.
    But, sometimes while searching, I want to skip few words (words are pvt, ltd, inc & ele). e.g. If I put "cough ltd" in any search box then while searching it will skip the "ltd". & will search the remaining word in file. But these words will skip only when there is "YES" in F3 coloumn If it is "NO" in F3 colomn then it will search the whole text ("cough ltd").
    Please help someone to write the program for this.
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Filter data w.r.t. different search input

    Please supply an actual excel question that you require help with.

    We are not a free code writing service.
    If you want somebody to actually do all the work for you, then check out our commercial services.

    https://www.excelforum.com/commercial-services/

  3. #3
    Registered User
    Join Date
    11-26-2018
    Location
    india
    MS-Off Ver
    2007
    Posts
    22

    Re: Filter data w.r.t. different search input

    Hello, I have created the code for individual search & total search. Please refer attached excel with code. But after any search if I change the color of any row (e.g. If I change the color of one row in yellow color) then again in next search if that row found in next search then that yellow color will again changed to Red (i.e. Red color which I keep for filter row.Can someone help me to skip the row which has color other than red (color=255) while filtering?

    Individual search code is prepared as below:
    Sub search_1()
    Dim srchtxt1 As String
    finRow = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
    fincol = Sheets(1).Cells(10, Columns.Count).End(xlToLeft).Column
    srchtxt1 = Sheets(1).Cells(1, 1).Text
    Sheets(1).Cells.Interior.ColorIndex = 0
    For j = 10 To finRow
    For i = 1 To fincol
    If ((InStr(LCase(Sheets(1).Cells(j, i).Text), LCase(srchtxt1))) >= 1) Then
    Rows(j).Interior.Color = 255
    'If Not ActiveSheet.AutoFilterMode Then
    'Sheets(1).Range(j, i).AutoFilter
    'End If
    End If
    Next i
    Next j
    Range("A10:P10").Select
    Selection.AutoFilter
    Range("A10").Select
    ActiveSheet.Range("$A$10:$P$18").AutoFilter Field:=1, Criteria1:=RGB(255, 0 _
    , 0), Operator:=xlFilterCellColor
    End Sub

    Comeplete Search code is as below:
    Sub total_search()
    Dim srchtxt1 As String
    Dim srchtxt2 As String
    Dim srchtxt3 As String
    Dim srchtxt4 As String
    Dim srchtxt5 As String
    Dim cntr1, cntr2, cntr3, cntr4, cntr5, srcnt1, srcnt2, srcnt3, srcnt4, srcnt5 As Integer
    finRow = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
    fincol = Sheets(1).Cells(10, Columns.Count).End(xlToLeft).Column

    Sheets(1).Cells.Interior.ColorIndex = 0

    If (IsEmpty(Sheets(1).Cells(1, 1)) = False) Then
    srchtxt1 = Sheets(1).Cells(1, 1).Text
    cntr1 = cntr1 + 1
    End If
    If (IsEmpty(Sheets(1).Cells(2, 1)) = False) Then
    srchtxt1 = Sheets(1).Cells(2, 1).Text
    cntr1 = cntr1 + 1
    End If
    If (IsEmpty(Sheets(1).Cells(3, 1)) = False) Then
    srchtxt2 = Sheets(1).Cells(3, 1).Text
    cntr1 = cntr1 + 1
    End If
    If (IsEmpty(Sheets(1).Cells(4, 1)) = False) Then
    srchtxt1 = Sheets(1).Cells(4, 1).Text
    cntr1 = cntr1 + 1
    End If
    If (IsEmpty(Sheets(1).Cells(5, 1)) = False) Then
    srchtxt1 = Sheets(1).Cells(5, 1).Text
    cntr1 = cntr1 + 1
    End If
    For j = 10 To finRow
    srcnt1 = 0
    srcnt2 = 0
    For i = 1 To fincol
    If ((IsEmpty(Sheets(1).Cells(1, 1)) = False And (InStr(LCase(Sheets(1).Cells(j, i).Text), LCase(srchtxt1))) >= 1)) Then
    'Rows(j).Interior.Color = 255
    'If Not ActiveSheet.AutoFilterMode Then
    'Sheets(1).Range(j, i).AutoFilter
    'End If
    srcnt1 = 1
    End If
    If ((IsEmpty(Sheets(1).Cells(2, 1)) = False And (InStr(LCase(Sheets(1).Cells(j, i).Text), LCase(srchtxt2))) >= 1)) Then
    srcnt2 = 1
    End If
    If ((IsEmpty(Sheets(1).Cells(3, 1)) = False And (InStr(LCase(Sheets(1).Cells(j, i).Text), LCase(srchtxt3))) >= 1)) Then
    srcnt3 = 1
    End If
    If ((IsEmpty(Sheets(1).Cells(4, 1)) = False And (InStr(LCase(Sheets(1).Cells(j, i).Text), LCase(srchtxt4))) >= 1)) Then
    srcnt4 = 1
    End If
    If ((IsEmpty(Sheets(1).Cells(5, 1)) = False And (InStr(LCase(Sheets(1).Cells(j, i).Text), LCase(srchtxt5))) >= 1)) Then
    srcnt5 = 1
    End If
    Next i
    cntr2 = srcnt1 + srcnt2 + srcnt3 + srcnt4 + srcnt5
    If (cntr1 = cntr2 And cntr1 >= 1) Then
    Rows(j).Interior.Color = 255
    End If
    Next j
    Range("A10:P10").Select
    Selection.AutoFilter
    Range("A10").Select
    ActiveSheet.Range("$A$10:$P$18").AutoFilter Field:=1, Criteria1:=RGB(255, 0 _
    , 0), Operator:=xlFilterCellColor
    End Sub

    Please help.
    Attached Files Attached Files

+ 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. [SOLVED] VBA to filter source column by search field input and/or conditional formatted cell color
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2016, 12:53 PM
  2. Replies: 1
    Last Post: 02-18-2015, 11:43 AM
  3. Replies: 4
    Last Post: 11-08-2014, 04:57 AM
  4. Replies: 2
    Last Post: 10-07-2013, 04:57 AM
  5. Return Data via Input Search Box
    By RicktheBlade in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2012, 09:31 PM
  6. Filter data automatically by input
    By Bunson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-28-2006, 03:30 PM

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