+ Reply to Thread
Results 1 to 4 of 4

Thread: "New" MsgBox/TextBox Question

  1. #1
    Registered User
    Join Date
    03-25-2008
    Location
    Indianapolis, Indiana
    Posts
    6

    "New" MsgBox/TextBox Question

    I found this during testing and don't understand why it is happening or how to fix it.

    Situation: Data column is 'empty', I type in a title and as it is supposed to, "Not Found" is returned when I click 'Search'. If I type in a single letter the same, "Not Found". Now the problem, if I type in a single number such as "2" or several nembers in a row "123" I get a return of "Found". If I type in "123a" I get a return of "Not Found" as I should.

    Again, when a single number or several numbers in a row are typed into the TextBox I get "Found". Why is this and how do I fix it? Any suggestions?

    Below is the block of code thats doing the search.

    Regards

       With Worksheets("Sheet1").Range("B2:B5040")
    
    Set c = Cells.Find(Me.TextBox1.Text, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=True)
        
    If Not c Is Nothing Then

  2. #2
    Forum Guru mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,984
    It could be because your find command is searching every cell of the sheet not just the With range that you posted

    To search the just the with range

    use
    Set c = .Find(Me.TextBox1.Text, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=True)
    or

    Set c = Worksheets("Sheet1").Range("B2:B5040").Cells.Find(Me.TextBox1.Text, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=True)
    You might also like to add
    msgbox c.address
    after the find & if not commands to see where it finding your text
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    03-25-2008
    Location
    Indianapolis, Indiana
    Posts
    6

    "New" MsgBox/TextBox Question

    Mudraker....Thanks for your reply, your input worked like a charm. I was under the impression that the above "with" statement was catching the range I intended to match. Never to old to learn.

    I don't know if you noticed or not but I found a work-around for my previous post.

    Again, Thanks for you help.

  4. #4
    Forum Guru mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,984
    Again I am glad to have been able to assist. & yes I did see that you had a work arround

    Your correct about never being to old to learn. For 1 I am still learning quicker & easier ways of writing code.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0