Find the value by TextBox..

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,236
Office Version
  1. 2013
Platform
  1. Windows
Code:
Dim ws As Worksheet, rngFind As Range
Set ws = ThisWorkbook.Sheets("staff")
Set rngFind = ws.Range("i:i").Find(what:=Me.TextBox2.Value, MatchCase:=True)
If Not rngFind Is Nothing Then
Me.TextBox20.Value = rngFind.Offset(0, 1).Value
Me.TextBox21.Value = rngFind.Offset(0, 2).Value
Else
Me.TextBox20.Value = "Not Found!"
TextBox21 = ("")
End If

Could someone help me to improve that given code above?
Its simply find column B value by entering the column A value into the TextBox2.Everything fine with that if the value is single like a name or ID number.....
My question is how can i make it more functional , like if the name is with 3 names and the user want to seach by second name or 3th?
If the name on column B ; Roberto Carlos Gonzales and if i type the Carlos name on TextBox2 then whole name will be find.
Hope its clear!
Many Thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try replacing...

Code:
Set rngFind = ws.Range("i:i").Find(what:=Me.TextBox2.Value, MatchCase:=True)

with

Code:
Set rngFind = ws.Range("i:i").Find(what:=Me.TextBox2.Value, [COLOR="Red"]LookAt:=xlPart[/COLOR], MatchCase:=True)
 
Upvote 0
Thanks for your reply but its not working ...
Some of the names are not in order , like (Mary,Jane.. Basco.)
Is that one could be the reason?
Thanks
 
Upvote 0
I've just re-read your original post, and it's a little confusing. If Column A contains names, such as "Roberto Carlos Gonzales", and the TextBox contains a value for which to search, such as "Carlos", try...

Code:
= ws.Range("[COLOR="Red"]a:a[/COLOR]").Find(what:=Me.TextBox2.Value, LookAt:=xlPart, MatchCase:=True)

Also, note that MatchCase is set to True, so Find is case-sensitive. If you don't want the search to be case-sensitive, set it to False.
 
Upvote 0
I've just re-read your original post, and it's a little confusing. If Column A contains names, such as "Roberto Carlos Gonzales", and the TextBox contains a value for which to search, such as "Carlos", try...

Code:
= ws.Range("[COLOR=red]a:a[/COLOR]").Find(what:=Me.TextBox2.Value, LookAt:=xlPart, MatchCase:=True)

Also, note that MatchCase is set to True, so Find is case-sensitive. If you don't want the search to be case-sensitive, set it to False.

Thanks Domenic,
 
Upvote 0

Forum statistics

Threads
1,203,187
Messages
6,053,992
Members
444,696
Latest member
VASUCH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top