PDA

View Full Version : [SOLVED] Cap sensitive search



lucas
02-28-2005, 04:13 PM
I'm using a textbox entry to search a listbox with code I yoinked from one of Drj's posts. I have been trying to figure out how to make this search not be cap sensitive with no luck.


Private Sub TextBox2_Change()
Dim Search As String
Dim n As Long
Dim i As Long
Dim j As Long
Search = Me.TextBox2.Text
n = Len(Me.TextBox2)
j = Me.lstSelection.ListCount - 1
For i = 0 To j
If Left(Me.lstSelection.List(i), n) = Search Then
Me.lstSelection.Selected(i) = True
Exit For
End If
Next
End Sub

mdmackillop
02-28-2005, 04:16 PM
Insert "Option Compare Text" at the top of your module

lucas
02-28-2005, 04:38 PM
Thanks MD,
I was trying to do it in the module. This works great.:hi:

Anne Troy
02-28-2005, 04:40 PM
ROFLMFAO!!! http://www.vbaexpress.com/forum/showthread.php?p=17433

mdmackillop
02-28-2005, 05:00 PM
Glad to help.
Another way to do it is to convert your text to upper (Ucase) or lower case (Lcase)
eg

if Ucase(text) = Ucase(Search Item) then...
but I think "Compare Text" is easier.

lucas
02-28-2005, 05:05 PM
:clever:

:devil:
Heh Heh......

Norie
02-28-2005, 06:59 PM
I don't know if this will help but it is something I did for somebody on www.mrexcel.com (http://www.mrexcel.com)

By the way not the link the attached file.

lucas
03-01-2005, 02:09 PM
Norie,
I think your code is developed along the lines that MD was talking about and it works nicely. I now can tackle this problem either way.

If UCase(Left(wsMeds.Range("A" & I).Text, L)) = UCase(txtStart) Then
lst.AddItem wsMeds.Range("A" & I).Text

Zack Barresse
03-01-2005, 02:50 PM
Great to see you here Norie!! :yes