Pinkster69
New Member
- Joined
- Jun 19, 2012
- Messages
- 48
Hi Guys,
Really need someones help on this!
I have a listbox "EventNameListBox" with contents displaying info on clothing etc that gets its info from Sheet2, all works well but I need is to filter the contents in the listbox even further.
I need to filter the contents in the list box to display "for example" all list items that have a certain Style number for which pre-populted in a separate Textbox "StyleNumberTextBox".
Below is the sample code I used to populate the list box.
Really hope you can help guys??
NB: Textbox2 is a date the listbox module etc is initially initiated with.
Really need someones help on this!
I have a listbox "EventNameListBox" with contents displaying info on clothing etc that gets its info from Sheet2, all works well but I need is to filter the contents in the listbox even further.
I need to filter the contents in the list box to display "for example" all list items that have a certain Style number for which pre-populted in a separate Textbox "StyleNumberTextBox".
Below is the sample code I used to populate the list box.
Really hope you can help guys??
NB: Textbox2 is a date the listbox module etc is initially initiated with.
Code:
Private Sub TextBox2_Change()
Dim strFind2 As String 'what to find
Dim FirstAddress2 As String
Dim rSearch2 As Range 'range to search
With Worksheets("Customer Data").Activate
Set rSearch2 = Sheet2.Range("L1", Range("l65536").End(xlUp)) 'Range of what you are looking for "this example its column "L",
strFind2 = Me.TextBox2.Value 'what to look for
With rSearch2
Set c2 = .Find(strFind2, LookIn:=xlValues)
If Not c2 Is Nothing Then 'found it
c2.Select
.StyleNumberTextBox.Value = c.Offset(0, 14).Value
FindAll
End If
End With
If Sheet2.AutoFilterMode Then Sheet2.Range("L2").AutoFilter
End With
End Sub
Sub FindAll()
Dim strFind2 As String 'what to find
Dim rFilter2 As Range 'range to search
Set rFilter2 = Sheet2.Range("a1", Range("aa65536").End(xlUp)) 'Range to look in
Set rng2 = Sheet2.Range("a1", Range("a65536").End(xlUp)) 'Range for the headings
strFind2 = Me.TextBox2.Value 'what to look for
'Sets the EventNameListBox ColumnCount to 27 as the properties panel only allows you 9 colouns in a List Box
Dim myArray As Variant
Me.EventNameListBox.ColumnCount = 27
myArray = rng2.Resize(, Me.EventNameListBox.ColumnCount).Value
Me.EventNameListBox.List = myArray
With Sheet2
If Not .AutoFilterMode Then .Range("L2").AutoFilter
rFilter2.AutoFilter Field:=12, Criteria1:=strFind2 'Must change the field value when looking for values in a differant column
Set rng2 = rng2.Cells.SpecialCells(xlCellTypeVisible)
Me.EventNameListBox.Clear
For Each c2 In rng2
With Me.EventNameListBox
.AddItem c2.Value
'Displays info on worksheet in the listbox
.List(.ListCount - 1, 0) = Format(c2.Offset(0, 0).Value, "dd/mm/yyyy")
.List(.ListCount - 1, 1) = c2.Offset(0, 1).Value
.List(.ListCount - 1, 2) = c2.Offset(0, 2).Value
.List(.ListCount - 1, 3) = c2.Offset(0, 3).Value
.List(.ListCount - 1, 4) = c2.Offset(0, 4).Value
.List(.ListCount - 1, 5) = c2.Offset(0, 5).Value
.List(.ListCount - 1, 6) = c2.Offset(0, 6).Value
.List(.ListCount - 1, 7) = c2.Offset(0, 7).Value
.List(.ListCount - 1, 8) = c2.Offset(0, 8).Value
.List(.ListCount - 1, 9) = c2.Offset(0, 9).Value
.List(.ListCount - 1, 10) = c2.Offset(0, 10).Value
.List(.ListCount - 1, 11) = Format(c2.Offset(0, 11).Value, "dd/mm/yyyy")
.List(.ListCount - 1, 12) = Format(c2.Offset(0, 12).Value, "dd/mm/yyyy")
.List(.ListCount - 1, 13) = c2.Offset(0, 13).Value
.List(.ListCount - 1, 14) = c2.Offset(0, 14).Value
.List(.ListCount - 1, 15) = Format(c2.Offset(0, 15).Value, "€#,##0.00")
.List(.ListCount - 1, 16) = Format(c2.Offset(0, 16).Value, "€#,##0.00")
.List(.ListCount - 1, 17) = Format(c2.Offset(0, 17).Value, "€#,##0.00")
.List(.ListCount - 1, 18) = Format(c2.Offset(0, 18).Value, "€#,##0.00")
.List(.ListCount - 1, 19) = c2.Offset(0, 19).Value
.List(.ListCount - 1, 20) = Format(c2.Offset(0, 20).Value, "dd/mm/yyyy")
.List(.ListCount - 1, 21) = Format(c2.Offset(0, 21).Value, "€#,##0.00")
.List(.ListCount - 1, 22) = c2.Offset(0, 22).Value
.List(.ListCount - 1, 23) = c2.Offset(0, 23).Value
.List(.ListCount - 1, 24) = c2.Offset(0, 25).Value
.List(.ListCount - 1, 25) = c2.Offset(0, 26).Value
End With
Next c2
End With
End Sub
Last edited: