1
votes

I am using a combobox in a userform that shows value from a certain cell, I use application.match to match its corresponding rows to be shown in other textbox

This is my code for combobox:

Private Sub ComboBox1_Change()

    If Me.ComboBox1.Value <> "" Then
        Dim sh As Worksheet
        Set sh = ThisWorkbook.Sheets("Student Profile")

        Dim i As Integer

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

        Me.TextBoxAddress.Value = sh.Range("D" & i).Value
        Me.TextBoxContact.Value = sh.Range("E" & i).Value
        Me.TextBoxName.Value = sh.Range("B" & i).Value
        Me.TextBoxSection.Value = sh.Range("C" & i).Value '''

    End If

The error says:

runtime error 13: type mismatch.

What seems to be the problem?

1

1 Answers

0
votes

please try this code

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