Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Searching for text or numbers in textbox

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching for multiple numbers darnduk Excel Worksheet Functions 3 November 26th 08 10:29 PM
Searching for duplicate numbers Uncle Guinness Excel Worksheet Functions 2 August 10th 06 10:59 PM
Searching numbers in Worksheet Johncobb45 Excel Worksheet Functions 6 August 5th 06 08:00 PM
Searching numbers in Worksheet? Johncobb45 Excel Worksheet Functions 2 July 31st 06 10:02 AM
Searching numbers in Worksheet? Johncobb45 Excel Worksheet Functions 3 July 28th 06 07:07 PM


All times are GMT +1. The time now is 03:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"