Find Method; First letter

C

CG Rosén

Good Day Group,

Can anyone help me with following; Trying to make a listbox filled with all
items that
have a selected letter, in textbox1, as its first letter. Below code seems
to list all items that have
the selected letter anywhere in its spelling.

Thanks and Brgds

CG Rosén

----------------------------------------------------------------------------
--------------
Dim s As String

ListBox1.Clear

With Worksheets(2).Range("B1:B231")
Set j = .Find(UserForm1.TextBox1.Text, LookIn:=xlValues,
SearchOrder:=xlByRows)

If Not j Is Nothing Then
firstAddress = j.Address
Do
r = j.Row
s = Sheets("c").Cells(r, 2)
ListBox1.AddItem s
Set j = .FindNext(j)
Loop While Not j Is Nothing And j.Address <> firstAddress

End If

End With
 
T

Tom Ogilvy

With Worksheets(2).Range("B1:B231")
Set j = .Find(Left(UserForm1.TextBox1.Text,1) & "*", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Additem problem 2
For Next does not find dates? 3
Nested loops?? 1
unique text additem combobox 1
Search engin 5
Listbox value return from search 3
Array and optionbutton? 1
hyperlink in listbox 6

Top