Combo Box Typing and Auto Completion in Number

nandhavnk

New Member
Joined
Jul 18, 2019
Messages
14
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I have coded wages report with ID No selection in combo box.

What I expecting is When I typing 1 in combo box, display 1 related numbers and then click tab button related name in textbox.

Here these changes happening in scrolling or mouse clicking options only.

Can experts guide me to sorting out this.

Here Code is,
VBA Code:
Private Sub cbanoO_change()
  Dim f As Range
  txtdelO.Value = ""
  txtdateO.Value = ""
  'Now go through and check the values of the first column against what was selected in the combo box.
  If cbanoO.ListIndex > -1 Then
    Set f = Sheets("Sheet1").Range("A:A").Find(CDbl(cbanoO.Value), , xlValues, xlWhole)
    If Not f Is Nothing Then
      txtdelO.Value = Sheets("Sheet1").Range("D" & f.row).Value
    End If
  End If
  'sorting in ascending
  With Me.cbanoO
    For X = LBound(.List) To UBound(.List)
        For Y = X To UBound(.List)
            If .List(Y, 0) + 0 < .List(X, 0) + 0 Then
                blah = .List(Y, 0)
                .List(Y, 0) = .List(X, 0)
                .List(X, 0) = blah
            End If
        Next Y
    Next X
  End With
End Sub

Private Sub UserForm_Activate()
  Dim dic As Object
  Dim i As Long
 
  Set dic = CreateObject("Scripting.Dictionary")
  With Sheets("Sheet1")
    For i = 3 To .Range("A" & Rows.Count).End(3).row
      dic(.Range("A" & i).Value) = Empty
    Next
  End With
cbanoO.List = dic.keys
txtdelO.Enabled = False
End Sub

Combo Box - Auto Selection with Number.xlsm
ABCDEFGHIJKLMNO
1Monthly Wages List
2ID NoDateDurationNameWages
311-Nov-228:00Araminta1000.00
421-Nov-227:00Arden875.00
531-Nov-225:00Azalea625.00
641-Nov-226:00Birch750.00
751-Nov-226:30Birdie812.50
861-Nov-227:30Blythe937.50
971-Nov-227:45Booker968.75
1081-Nov-228:00Catherine1000.00
1191-Nov-223:00Clover375.00
12101-Nov-225:00Dane625.00
13111-Nov-225:30Garrison687.50
14121-Nov-223:30Hale437.50
15131-Nov-226:30Jump812.50
16141-Nov-227:30Kit937.50
17151-Nov-227:45Lavender968.75
18161-Nov-221:45Lilac218.75
19171-Nov-222:00Mary250.00
20181-Nov-225:15Micheal656.25
21191-Nov-227:15Nick906.25
22201-Nov-221:30Oberon187.50
23211-Nov-228:00Peter1000.00
24221-Nov-225:00Posey625.00
25231-Nov-222:00Shaw250.00
26241-Nov-226:30Tobin812.50
27251-Nov-228:00Waverly1000.00
28261-Nov-228:00Winston1000.00
29102-Nov-222:00Dane250.00
3092-Nov-228:00Clover1000.00
31132-Nov-225:00Jump625.00
Sheet1
Cell Formulas
RangeFormula
C3,C30,C27:C28,C23,C10C3=8/24
C4C4=7/24
C5,C31,C24,C12C5=5/24
C6C6=6/24
C7,C26,C15C7=6.5/24
C8,C16C8=7.5/24
C9,C17C9=7.75/24
C11C11=3/24
C13C13=5.5/24
C14C14=3.5/24
C18C18=1.75/24
C19,C29,C25C19=2/24
C20C20=5.25/24
C21C21=7.25/24
C22C22=1.5/24
E3:E31E3=(C3*24)*125


UserForm Screenshot is,
Order Form.png


Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Check if the following works for you.
If you want to display any captured number use this:
VBA Code:
If ky Like "*" & dato & "*" Then

If you want only what starts with the captured number use this:
VBA Code:
If ky Like dato & "*" Then

I recommend you sort the data in the sheet before opening the userform. When you close the userform, order the data again as you want.

Change all your code to this:

VBA Code:
Option Explicit

Dim a As Variant
Dim cargando As Boolean
Dim dic As Object

Private Sub cbanoO_change()
  Dim dato As String
  Dim ky As Variant
  
  If cargando = True Then Exit Sub
  txtdelO.Value = ""
  txtdateO.Value = ""
  cargando = True
  dato = cbanoO.Value
  cbanoO.Clear
  For Each ky In dic.keys
    If ky Like "*" & dato & "*" Then
      cbanoO.AddItem ky
    End If
  Next
  cbanoO.Value = dato
  '
  If cbanoO.ListIndex > -1 Then
    txtdelO.Value = a(dic(Val(cbanoO.Value)), 4)
  End If
  txtdateO.SetFocus
  cbanoO.SetFocus
  cbanoO.DropDown
  cargando = False
End Sub

Private Sub UserForm_Activate()
  Dim i As Long
 
  Set dic = CreateObject("Scripting.Dictionary")
  With Sheets("Sheet1")
    a = .Range("A3:E" & .Range("A" & Rows.Count).End(3).Row).Value
    For i = 1 To UBound(a, 1)
      dic(a(i, 1)) = i
    Next
  End With
  cbanoO.List = dic.keys
  cbanoO.MatchEntry = fmMatchEntryNone
  txtdelO.Enabled = False
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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