Search code examples
vbacomboboxmatchlookup

VBA Match Function on combo box


I am trying to get a form to populate data from a sheet using cell Z as the lookup reference.

The dropdown on the form showing my list of issue references works. When I select an item from said list to populate the form I get the mismatch error.

Also, my range in Z column is a mix of letters and numbers. I did change I to variant but no luck

The application.match is returning an error. Any ideas?

Run Time error '13': Type Mismatch

Private Sub ComboBox2_Change()
    If Me.ComboBox2.Value <> "" Then
        Dim sh As Worksheet
        Set sh = ThisWorkbook.Sheets("Inbound Issues")
        Dim i As Integer
        i = Application.Match(VBA.CLng(Me.ComboBox2.Value), sh.Range("Z:Z"), 0)
        Me.TextBox1.Value = sh.Range("H" & i).Value
    End If
End Sub

Solution

  • Private Sub ComboBox2_Change() If Me.ComboBox2.Value <> "" Then Dim sh As Worksheet Set sh = ThisWorkbook.Sheets("Inbound Issues") Dim i As Integer i = Application.Match(VBA.Str(Me.ComboBox2.Value), sh.Range("Z:Z"), 0) Me.TextBox1.Value = sh.Range("H" & i).Value End If End Sub

    Change Clng to Str