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
Search engin 5
unique text additem combobox 1
Problem with hyperlink macro 0
listbox multiple selections 1
ListBox MultiSelectMulti mode 1

Top