I utilize a ComboBox to allow the user to choose a value from ONE column on Sheet2. The value they choose then gets used in a "FILTER" process to only show the rows with the value chosen in ComboBox1. If the row does NOT contain the same value in ComboBox1, the entire row is hidden. Basically, I have a Worksheets with LOADS of data, by using a ComboBox and the FILTER code, I am allowing the user to VIEW ONLY the data they want to see based on what value they have chosen in ComboBox1. Here comes the NEXT PHASE question....
I would like to allow the user to have multiple criteria choices in order to filter the sheet from. Right now, ComboBox1 has a ListFillRange from one column. Once the user chooses a value as the filter criteria, the FILTER CommandButton is clicked and any row that doesn't have that value in it gets hidden. Here is the FILTER code I have used:
Private Sub CommandButton1_Click()
Dim myVal As String, i As Long, lastRow As Long
myVal = ComboBox1.Value
With Sheets("Sheet3")
.Cells.EntireRow.Hidden = False
lastRow = .Range("A65536").End(xlDown).Row
For i = 1 To lastRow
If .Cells(i, "D") = myVal Then
.Rows(i).Hidden = False
Else
.Rows(i).Hidden = True
End If
Next i
End With
Sheets("Sheet3").Select
End Sub
First problem, If I utilize MULTIPLE ComboBoxes, how can I edit the above code to search for the values from BOTH ComboBoxes? Do I simply make the following change to the above code:
myVal = ComboBox1.Value And ComboBox2.Value
Next question, would it be easier to use a ListBox? If so, how?
Yes, I am sure that I may have to explain this a bit better, but for now, I am not finding the right wording. Simply stated, I want to give the user more choices to choose from in order to focus the data they want to view. There are many rows that have the same value in the one column I am using as the ListFillRange for ComboBox1. In order to provide a more robust tool, I need to provide another column of data and have the above Filter code filter the worksheet of the value from both ComboBoxes.
Hope this make sense. If not, I am here for questions. Thanks in advance for the help.
I would like to allow the user to have multiple criteria choices in order to filter the sheet from. Right now, ComboBox1 has a ListFillRange from one column. Once the user chooses a value as the filter criteria, the FILTER CommandButton is clicked and any row that doesn't have that value in it gets hidden. Here is the FILTER code I have used:
Private Sub CommandButton1_Click()
Dim myVal As String, i As Long, lastRow As Long
myVal = ComboBox1.Value
With Sheets("Sheet3")
.Cells.EntireRow.Hidden = False
lastRow = .Range("A65536").End(xlDown).Row
For i = 1 To lastRow
If .Cells(i, "D") = myVal Then
.Rows(i).Hidden = False
Else
.Rows(i).Hidden = True
End If
Next i
End With
Sheets("Sheet3").Select
End Sub
First problem, If I utilize MULTIPLE ComboBoxes, how can I edit the above code to search for the values from BOTH ComboBoxes? Do I simply make the following change to the above code:
myVal = ComboBox1.Value And ComboBox2.Value
Next question, would it be easier to use a ListBox? If so, how?
Yes, I am sure that I may have to explain this a bit better, but for now, I am not finding the right wording. Simply stated, I want to give the user more choices to choose from in order to focus the data they want to view. There are many rows that have the same value in the one column I am using as the ListFillRange for ComboBox1. In order to provide a more robust tool, I need to provide another column of data and have the above Filter code filter the worksheet of the value from both ComboBoxes.
Hope this make sense. If not, I am here for questions. Thanks in advance for the help.