maabadi
Well-known Member
- Joined
- Oct 22, 2012
- Messages
- 2,681
- Office Version
- 2019
- 2016
- Platform
- Windows
Hi
I want to use Backspace key to delete last letter typed on combobox2, but it show error "type mismatch"
This is code for userform:
I want to use Backspace key to delete last letter typed on combobox2, but it show error "type mismatch"
This is code for userform:
Code:
Private Sub UserForm_Initialize()
Me.ComboBox2.List = Worksheets("Sheet2").Range("B2:B600").Value
Dim ws As Worksheet, rCell As Range, Key
Dim Dic As Object: Set Dic = CreateObject("Scripting.Dictionary")
Set ws = Worksheets("Sheet2")
AddNewLineorHybrid.ComboBox2.Clear
For Each rCell In ws.Range("B2", ws.Cells(Rows.Count, "B").End(xlUp))
If Not Dic.exists(LCase(rCell.Value)) Then
Dic.Add LCase(rCell.Value), Nothing
End If
Next rCell
For Each Key In Dic
AddNewLineorHybrid.ComboBox2.AddItem Key
Next
End Sub
Private Sub ComboBox2_Change()
Dim ws As Worksheet
Set ws = Worksheets("Sheet2")
Me.TextBox1.Value = Evaluate("VLOOKUP(""" & Me.ComboBox2 & """,Sheet2!B:C,2,FALSE)")
End Sub
Private Sub TextBox1_Change()
Worksheets("Sheet1").Range("B2").Value = TextBox1.Value
End Sub
Private Sub Combobox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 8 'Baskspace
If Len(ComboBox2) > 0 Then
ComboBox2 = Left(ComboBox2, Len(ComboBox2) - 1)
End If
Case 9 'Tab
ActiveCell.Offset(0, 1).Activate
Case 13 'Enter
ActiveCell.Offset(1, 0).Activate
Case Else
'do nothing
End Select
End Sub