我是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
的日期答案 0 :(得分: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