Excel VBA:类型不匹配说明

问题描述 投票:0回答:1

我是VBA的新手,所以希望有更多经验的人能解释我收到的原因

键入不匹配错误

针对以下内容:

Private Sub cbbWeek_Change()
txtWeekEnding = Application.VLookup(cbbWeek.Value, Worksheets("Formulas").Range("Q1:R53"), 2, False)
End Sub

我不确定它是否相关但是;

列Q包含从1(在单元格Q1中)到52(在单元格Q52中)的数字列R包含格式化为dd / mm / yyyy的日期

excel vba excel-vba
1个回答
3
投票

要查看VLookup是否返回错误 - 将返回的值赋给变量。检查变量是否是错误,如果不是错误 - 将其分配给txtWeekending:

Private Sub TestMe()

    Dim checker         As Variant
    Dim txtWeekending   As Variant

    checker = Application.VLookup("vityata", Range("A1:C53"), 2, False)
    If Not IsError(checker) Then
        Debug.Print checker
        txtWeekending = checker
    Else
        Debug.Print checker
    End If

End Sub

This is an article from CPearson, concerning the same problem

© www.soinside.com 2019 - 2024. All rights reserved.