LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default search and display

TK,

You could use the change event of the textbox to constantly update the listbox... try the code
below. (Or you could use the code in a commandbutton.click event to update the list only when the
user is finished entering the search term.) Note that the search is done looking for the left-most
letters: you could also look for the string anywhere by changing

myFindString = strTBVAlue & "*"

to

myFindString = "*" & strTBVAlue & "*"

--
HTH,
Bernie
MS Excel MVP


Private Sub TextBox1_Change()
Dim c As Range ' The cell found with what you want
Dim d As Range ' All the cells found with what you want
Dim myFindString As String
Dim firstAddress As String
Dim strTBVAlue As String
Dim myCell As Range
Dim myArr() As String
Dim i As Integer

strTBVAlue = UserForm1.TextBox1.Text

myFindString = strTBVAlue & "*"

With Worksheets("Sheet1").Range("A:A")

Set c = .Find(myFindString, LookIn:=xlValues, lookAt:=xlWhole)

If Not c Is Nothing Then
Set d = c
firstAddress = c.Address
Else:
ReDim myArr(1 To 1)
myArr(1) = ""
UserForm1.ListBox1.List = myArr
MsgBox "No cells found with that sub-string."
End If

Set c = .FindNext(c)
If Not c Is Nothing And c.Address < firstAddress Then
Do
Set d = Union(d, c)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

i = 0
ReDim myArr(1 To d.Cells.Count)
For Each myCell In d
i = i + 1
myArr(i) = myCell.Value
Next myCell

UserForm1.ListBox1.List = myArr
End Sub


"tkraju via OfficeKB.com" <u16627@uwe wrote in message news:648c7e1a0a437@uwe...
I am looking for code that search a string,say first 3 letters of a
textboxvalue, from a range,and retuns all matching values in a searchresults
listbox.suppose user enters 'smi' in a inputbox all the valid serch results
in that range should populate in a list box.,say 'smith','smiron','smile',

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200608/1



 
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
Search multiple columns and display corresponding cells in a list?!? far2rare Excel Discussion (Misc queries) 9 July 4th 06 11:46 PM
to search and display the top 50s (from the previous 14 sheets) in a new sheet joyjoy329 Excel Worksheet Functions 2 July 4th 06 03:33 PM
Search and Display Formula koba Excel Discussion (Misc queries) 1 November 10th 05 12:19 AM
Macro to search for and display data in another worksheet Mark H Excel Worksheet Functions 0 June 14th 05 12:40 PM
Search and Display Sheet Name jtinne Excel Discussion (Misc queries) 5 February 4th 05 09:08 PM


All times are GMT +1. The time now is 11:15 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"