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
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
orSet c = .Find(Me.TextBox1.Text, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=True)
You might also like to addSet c = Worksheets("Sheet1").Range("B2:B5040").Cells.Find(Me.TextBox1.Text, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=True)
after the find & if not commands to see where it finding your textmsgbox c.address
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 assistedor failed to assist you
I welcome your Feedback.
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.
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 assistedor failed to assist you
I welcome your Feedback.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks