Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Well, as I under stand, you want to enter a number of name in a text
box, and then click on a button, which will find corresponding name or number and add to the list box. Assuming the numbers and names are in column A and B in worksheet1 and number of rows of them are 1000, you can use following code in the commandbutton_click event. The below code checks first if the entered data is a number or text and accordingly puts name in case it is number or number in case it is name. Dim myRange As Range, foundRange As Range, findWhat As String Set myRange = Worksheets("Sheet1").Range("A1:B1000") findWhat = TextBox1.Text On Error Resume Next If IsNumeric(findWhat) Then Set foundRange = myRange.Find(What:=findWhat, LookAt:=xlWhole).Offset(0, 1) If Err < 0 Then MsgBox "The number you entered was not found in the list." Exit Sub End If ListBox1.AddItem (ListBox1.ListCount + 1 & ". " & foundRange.Value) Else Set foundRange = myRange.Find(What:=findWhat, LookAt:=xlWhole).Offset(0, -1) If Err < 0 Then MsgBox "The name you entered was not found in the list." Exit Sub End If ListBox1.AddItem (ListBox1.ListCount + 1 & ". " & foundRange.Value) End If Sharad *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Searching for multiple numbers | Excel Worksheet Functions | |||
Searching for duplicate numbers | Excel Worksheet Functions | |||
Searching numbers in Worksheet | Excel Worksheet Functions | |||
Searching numbers in Worksheet? | Excel Worksheet Functions | |||
Searching numbers in Worksheet? | Excel Worksheet Functions |