Application Match Error 13 I dont understand

222 Views Asked by At

I'm trying to find a solution of

application.match error code 13

this is just a simple code in vba, is someone who can can help me fixing this code

Private Sub cmbName_Change()

If Me.cmbName.Value <> "" Then
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets("DATABASE")
    Dim i As Integer


    i = Application.Match(VBA.CLng(Me.cmbName.Value), sh.Range("A:A"), 0)

    Me.txtDatepicker.Value = sh.Range("A" & y).Value
    Me.cmbAddress.Value = sh.Range("C" & i).Value
    Me.txtContact.Value = sh.Range("D" & j).Value
    Me.cmbEducation.Value = sh.Range("E" & i).Value
    Me.cmbSpecify.Value = sh.Range("F" & i).Value
    Me.txtAge.Value = sh.Range("G" & j).Value

    If sh.Range("H" & i).Value = "Male" Then Me.optMale.Value = True
    If sh.Range("H" & i).Value = "Female" Then Me.optFemale.Value = True

    Me.cmbTraining.Value = sh.Range("I" & i).Value
    Me.cmbEmployment.Value = sh.Range("J" & i).Value
    Me.txtOthers.Value = sh.Range("K" & i).Value
    Me.txtAction.Value = sh.Range("L" & i).Value
    Me.txtLivelihood.Value = sh.Range("M" & i).Value

End If

End Sub
1

There are 1 best solutions below

0
DecimalTurn On

Error code 13 stands for Type Mismatch.

Possibility 1

You get this error because you are passing a string that contains characters that can't be interpreted as number to the Clng function. Hence, it can't be converted to a long variable.

To solve this you could add some error handling to convert to a long only when Clng doesn't return an error or you could get rid of the Clng function all together and make sure that Column A is formatted as text (since that's the range you are matching to).

Possibility 2

You get this error because there is no cell in column A that matches the value in the combobox.

To solve this, you would need to add some error handling and decide what you want to do when there is no match.