首页 > 解决方案 > Application.Match 错误说类型不匹配

问题描述

我在用户窗体中使用一个组合框来显示来自某个单元格的值,我使用 application.match 来匹配要在其他文本框中显示的相应行

这是我的组合框代码:

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

错误说:

运行时错误 13:类型不匹配。

似乎是什么问题?

标签: excelvba

解决方案


请尝试此代码

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

推荐阅读