Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Select in Listbox using keystrokes

H

I have a ListBox in a UserForm that holds several elements, like

Englan
Leg
Lisabo
Londo
Madri
Mila
etc..

I would like to be able to select an entry by typing the name in a text-box I have placed above the Listbox. It should highlight the word I type in the listbox

Normally, by using keystrokes in the Listbox, typing "L" will highlight the first word with beginning with L. Typing "E" will highlight the first word beginning with "E". I would like the form to behave in a way so if I type "LE" it highlights the first word beginning with "LE" and so on

Is there a way to do that in a UserForm

//Sore


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Select in Listbox using keystrokes

Hi Soren,

Here's some starter code

Dim colList As Collection

Private Sub TextBox1_Change()
Dim i As Long

With TextBox1
For i = 1 To colList.Count
If LCase(.Text) = LCase(Left(colList.Item(i), Len(.Text))) Then
ListBox1.ListIndex = i - 1
Exit For
End If
Next i
End With

End Sub

Private Sub UserForm_Activate()
Dim col

Set colList = New Collection
With colList
.Add "England", "England"
.Add "Lego", "Lego"
.Add "Lisabon", "Lisabon"
.Add "London", "London"
.Add "Madrid", "Madrid"
.Add "Milan", "Milan"
End With

TextBox1.SetFocus
With ListBox1
For Each col In colList
.AddItem col
Next col
End With

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

wrote in message
...
Hi

I have a ListBox in a UserForm that holds several elements, like:

England
Lego
Lisabon
London
Madrid
Milan
etc...

I would like to be able to select an entry by typing the name in a

text-box I have placed above the Listbox. It should highlight the word I
type in the listbox.

Normally, by using keystrokes in the Listbox, typing "L" will highlight

the first word with beginning with L. Typing "E" will highlight the first
word beginning with "E". I would like the form to behave in a way so if I
type "LE" it highlights the first word beginning with "LE" and so on.

Is there a way to do that in a UserForm?

//Soren




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Select in Listbox using keystrokes

Thanks, it works perfectly :-

//Soren
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
Problem using INDEX to select items in listbox Shazbot Excel Discussion (Misc queries) 3 April 28th 06 09:06 AM
how to find out when a ListBox is populated or select it Valeria[_2_] Excel Programming 2 January 26th 04 12:31 PM
I need to select some values in a Listbox???? Angel[_3_] Excel Programming 0 January 22nd 04 02:26 PM
excel - ListBox multiple Select sjvenz Excel Programming 4 December 9th 03 08:52 AM
Select from table and listbox PawelR Excel Programming 1 November 7th 03 01:21 PM


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