Backspace for delete last letter on active part of userform

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
2,681
Office Version
  1. 2019
  2. 2016
Platform
  1. 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:
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
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Where in the code do you get the error?
 
Upvote 0
When I debug it it show yellow part this line:
Code:
Me.TextBox1.Value = Evaluate("VLOOKUP(""" & Me.ComboBox2 & """,Sheet2!B:C,2,FALSE)")

Run time Error '-2147352571 (80020005)' :
Could not set the property value, Type mismatch.
 
Upvote 0

Forum statistics

Threads
1,215,191
Messages
6,123,553
Members
449,108
Latest member
rache47

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