+ Reply to Thread
Results 1 to 4 of 4

How do I use check boxes to allow multiple search criteria?

Hybrid View

  1. #1
    Registered User
    Join Date
    07-10-2012
    Location
    Lincoln
    MS-Off Ver
    Excel 2003
    Posts
    3

    How do I use check boxes to allow multiple search criteria?

    Hello Everyone.
    This is my first post so I am not sure how everything works or if my title is correct, please let me know if anything needs changing. Anyway to my problem, I have a database on my second sheet and on the first sheet there is a selection of the important headings from the database.

    E.g
    sheet 1
    A B
    9 Report Failure Search Button CheckBox (linked to F9)

    10 Author PEH Search Button CheckBox (linked to F10)

    11 Search Button

    B9 Failure is selected from a drop down menu, if I click the search button then it will search the database for all failure reports. This works fine and will give you a list on sheet 3. This also works if I press the search button for the Author.

    My problem is I want to click the search button on row 11 and would like it search for both report and author when they are checked, there are more rows and search buttons which I have not shown. So when I would like it to search for which ever checkBoxes are checked. This is the code I have used, apologies it is a bit messy I am by no means an expert. This shows how it searches for a single variable. If you could please explain how I could make this search for the checked boxes I would be very grateful.
    Dim LSearchRow As Integer
        Dim LCopyToRow As Integer
        
        On Error GoTo Err_Execute
        
        Dim start As Integer
        Dim finish As Integer
        
        Dim val1 As String
       
        start = 1
        finish = 6000
        
        'Start search in row 4
        LSearchRow = 2
    
        'Start copying data to row 2 in Sheet2 (row counter variable)
        LCopyToRow = 3
        
        
        Application.ScreenUpdating = False
        'Unhides all columns from previous searches
        Sheets("sheet3").Select
       Columns("S").Select
        Selection.EntireColumn.Hidden = True
        
        
        Range("A3:AQ6000").Clear
        
        'Assigns Values to variables
        Sheets("sheet1").Select
        val1 = Range("B9").Value
       
       
        'Uses variables to assign data on the database sheet
        Sheets("sheet2").Select
        Range("Z1") = val1
      
        
        
        While start < finish
    
                    Sheets("sheet2").Select
            
            If Range("I" & CStr(LSearchRow)).Value = Range("Z1") Then
    
                
                'Select row in Sheet2 to copy
                Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
                Selection.Copy
    
                'Paste row into Sheet3 in next row
                Sheets("sheet3").Select
                Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
                ActiveSheet.Paste
    
                'Move counter to next row
                LCopyToRow = LCopyToRow + 1
    
                'Go back to Sheet1 to continue searching
                Sheets("sheet2").Select
    
            End If
          
            LSearchRow = LSearchRow + 1
            start = start + 1
            
    
        Wend
    
        'Position on cell A3
        Application.CutCopyMode = False
        Sheets("sheet3").Select
        Range("A2").Select
        Application.ScreenUpdating = True
        MsgBox "To Seach again please go back to the sheet1"
    
        Exit Sub
    
    Err_Execute:
        MsgBox "An error occurred."
    End Sub
    Again I would be greatful for any help.
    Last edited by GTengineer; 07-10-2012 at 09:28 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    04-30-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    547

    Re: How do I use check boxes to allow multiple search criteria?

    Hi, you should wrap your code in code tags like this
    [code] Your code [/code]

    Apart from that, it will be much easier to work on your issue if you can post a sample file with a few rows of dummy data.
    Like a post? Click the star below it!

  3. #3
    Registered User
    Join Date
    07-10-2012
    Location
    Lincoln
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How do I use check boxes to allow multiple search criteria?

    Thanks, I have made the code ajustment. I will make up a dummy file and attach it as well.

  4. #4
    Registered User
    Join Date
    07-10-2012
    Location
    Lincoln
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How do I use check boxes to allow multiple search criteria?

    As promised here is the test file, please feel free to change it as you wish. This problem really has me stumped!

    Test.xls

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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