Consulting

Results 1 to 9 of 9

Thread: Cap sensitive search

  1. #1
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    Cap sensitive search

    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
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Insert "Option Compare Text" at the top of your module

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    thats it!

    Thanks MD,
    I was trying to do it in the module. This works great.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    ~Anne Troy

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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.

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    Glad you enjoyed that Ann




    Heh Heh......
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    I don't know if this will help but it is something I did for somebody on www.mrexcel.com

    By the way not the link the attached file.

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    Thanks Norie and MD

    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
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Great to see you here Norie!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •