LittleRedOne
New Member
- Joined
- Nov 28, 2013
- Messages
- 4
Hi All,
I have a userform with a textbox (TbAdd6) and a cmd button. I have managed to search and list all the matches, in a new userform containing a listbox, using the cmd button and this works fine. However it will only find exact matches from the data entered in the textbox. How can work it so that it will display the results of a part match and not be case sensitive? Please can somebody help?
My code is as follows
Private Sub CommandButton17_Click()
Dim dataRange As Range
Dim oneCell As Range
With Sheets("Database").Range("B:B")
Set dataRange = Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With
UserForm9.ListBox1.Clear
For Each oneCell In dataRange
With oneCell.EntireRow
If CStr(.Range("G1").Value = UserForm1.TbAdd6.Value) Then
UserForm9.ListBox1.AddItem CStr(.Range("B1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 1) = CStr(.Range("C1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 2) = CStr(.Range("D1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 3) = CStr(.Range("E1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 4) = CStr(.Range("F1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 5) = CStr(.Range("G1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 6) = .EntireRow.Address(, , , True)
End If
End With
Next oneCell
UserForm9.Show
End Sub
I have a userform with a textbox (TbAdd6) and a cmd button. I have managed to search and list all the matches, in a new userform containing a listbox, using the cmd button and this works fine. However it will only find exact matches from the data entered in the textbox. How can work it so that it will display the results of a part match and not be case sensitive? Please can somebody help?
My code is as follows
Private Sub CommandButton17_Click()
Dim dataRange As Range
Dim oneCell As Range
With Sheets("Database").Range("B:B")
Set dataRange = Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With
UserForm9.ListBox1.Clear
For Each oneCell In dataRange
With oneCell.EntireRow
If CStr(.Range("G1").Value = UserForm1.TbAdd6.Value) Then
UserForm9.ListBox1.AddItem CStr(.Range("B1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 1) = CStr(.Range("C1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 2) = CStr(.Range("D1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 3) = CStr(.Range("E1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 4) = CStr(.Range("F1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 5) = CStr(.Range("G1").Value)
UserForm9.ListBox1.List(UserForm9.ListBox1.ListCount - 1, 6) = .EntireRow.Address(, , , True)
End If
End With
Next oneCell
UserForm9.Show
End Sub