Searching
I wrote this code some time ago that I think is what you want, it will just
need to be adapted.
Dim lastCell As Long
Private Sub ComboBox1_Change()
Rows("1:1").Select 'this is the row number of the header for the AutoFilter
Selection.AutoFilter
If ComboBox1 < "" Then Selection.AutoFilter Field:=1,
Criteria1:=ComboBox1.Value 'change the field to the Name column
End Sub
Private Sub ComboBox2_Change()
If ComboBox2 < "" Then Selection.AutoFilter Field:=2,
Criteria1:=ComboBox2.Value 'ditto for the date
End Sub
Private Sub CommandButton1_Click()
UserForm1.Hide
End Sub
Private Sub UserForm_Initialize()
Sheets("sheet1").AutoFilterMode = False 'turns off filter
lastCell = Cells(Rows.Count, "A").End(xlUp).Row 'this is the last cell with
data, change the "A" to the column with the names
For i = 2 To lastCell ' I start with 2 because the headers are in 1
ComboBox1.AddItem (Cells(i, 1)) 'this assumes Name is in Column 1 or A
ComboBox2.AddItem (Cells(i, 2)) 'this assumes the dates are in Column 2 or B
Next
End Sub
--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.
"Seb Warmoth" wrote:
Is there a way to have a selection of boxes each titled with a column in a
second sheet and then filter based on these. Basically, if someone types a
name in the box representing column C, is there a way to then go to the 2nd
sheet and see a pre-filtered sheet. Can this be done with multiple inputs to
filter it even more, such as a name in column C and a job in column D to get
a more defined search? Thanks
|