Использование поля ввода для проведения VLookUp - PullRequest
0 голосов
/ 20 апреля 2020

У меня постоянно возникает несоответствие типов при запуске кода. Я уже определил диапазон QB в Excel и не могу понять проблему. Любая помощь будет принята с благодарностью.

Private Sub cmdQB_Click()
    'define variables
    Dim strName As String, rank As String, rngQBs As Range
    Dim shtProjections As Worksheet
    Set shtProjections = Application.Workbooks("finalProjectProjections.xlsm").Worksheets("Projections")
    Set rngQBs = shtProjections.Range("QBs")

    strName = InputBox("Enter QB name", "QBs")
    If Len(strName) > 0 Then
        rank = Application.VLookup(strName, shtProjections.Range("QBs"), 1, False)
        MsgBox " & strName & ", "is ranked" & rank
    Else
        MsgBox "The player is not ranked."
    End If

End Sub

1 Ответ

1 голос
/ 20 апреля 2020
Private Sub cmdQB_Click()
    'define variables
    Dim strName As String, rank As Variant, rngQBs As Range
    Dim shtProjections As Worksheet
    Set shtProjections = Application.Workbooks("finalProjectProjections.xlsm").Worksheets("Projections")
    Set rngQBs = shtProjections.Range("QBs")

    strName = InputBox("Enter QB name", "QBs")
    If Len(strName) > 0 Then
        rank = Application.VLookup(strName, shtProjections.Range("QBs"), 1, False)
        If Not IsError(rank) Then
            MsgBox strName & ", is ranked" & rank
        Else
            MsgBox strName & " is not found in list"
        End If
    Else
        MsgBox "You did not enter a name"
    End If

End Sub
...