Combobox auto complete

Yogi

Board Regular
Joined
Oct 21, 2002
Messages
74
I have a worksheet named, "Database2". There are hundreds of names in colum B starting in row 3 of this worksheet.
In the same Workbook is a worksheet named, "Records". I want to create a userform with a combo box, an "Enter" and "Cancel" command button. When typing begins in the combo box I need it to recognize the name from the "Database2" list in colum B and executes auto complete. When the "Enter" button is clicked I need it to enter the name in the first available row in colum B starting in row 3 in the Worksheet named "Records".
Any help is greatly apreciated.
Thanks
 
Try adding:

<pre>
.MatchEntry = fmMatchEntryComplete
</pre>

in your With...End With clause. Or set the property manually.
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I tried adding
.MatchEntry = fmMatchEntryComplete
but it still did not perform the function. I'm not quiet sure how to set this property manually, but willing to learn.
Thanks
 
Upvote 0
Yogi

This property can be set on the combobox's property page(manually).
I currently have a post on a similar topic, maybe we can both get the answers we need.

Bob
 
Upvote 0
Yogi

There is probably nothing new here(it is more or less a summary of previous posts), but your last post suggested you had not yet achieved success. Anyways, I know this works.

On your worksheet "Database2", select the list in column B and call it "Names".
Create a userform with three controls, a combobox(cboNames) and two buttons(cmdEnter,cmdCancel).
Do not change any properties for the combobox except for the name.
In the code module for the Userform, place the following code:

<pre>Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdEnter_Click()
Dim lngRows As Long
Dim rngNextEmpty As Range
lngRows = Worksheets("Records").Rows.Count
Set rngNextEmpty = Worksheets("Records").Cells(lngRows, 2).End(xlUp).Offset(1, 0)
rngNextEmpty.Value = cboNames.Value
cboNames.SetFocus
End Sub

Private Sub UserForm_Initialize()
With cboNames
.Style = fmStyleDropDownList
.MatchEntry = fmMatchEntryComplete
.EnterFieldBehavior = fmEnterFieldBehaviorSelectAll
.RowSource = "Database2!Names"
.ListIndex = 0
End With
End Sub</pre>

If you want the form to be available when you move to the sheet named "Records", place this code in the code module for the sheet named "Records".
<pre>Private Sub Worksheet_Activate()
UserForm1.Show vbModeless
End Sub</pre>

Bob
 
Upvote 0
The formula offered by bobm worked great. Is there a way if "Enter" is pressed on the keyboard while the cursor is in the combobox that the value would be entered the same as clicking the "Enter" button?
Thanks
 
Upvote 0
Yogi

On the property pages for the three controls, make certain that these properties are set:

cboNames
Tab Index = 0

cmdEnter
Tab Index = 1
Default = True

cmdCancel
Tab Index = 2
Cancel = True

Now, when the user presses the Enter key, the code in your Enter button will execute.
If the user presses the Esc key, the code in your Cancel button executes.

Bob
This message was edited by bobm on 2003-01-23 03:47
 
Upvote 0
I have run into one minor problem. If the name isn't in the database2 it won't allow me to type the name. Is this something that can be overcome?
Thanks
 
Upvote 0
Hi Yogi,

In Bob's UserForm Initialize code,change the following line from:

.Style = fmStyleDropDownList

To:

.Style = fmStyleDropDownCombo


Jaafar.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top