为什么VLookUp一直返回错误2042?



这可能不是最聪明的转换" jan ";"1";从1月1日,2021"日期,但为什么VLookUp一直返回错误2042?

Option Explicit
Dim MonthMatrix(0 To 1, 0 To 11 As Variant
MonthMatrix(0, 0) = "Jan"
MonthMatrix(1, 0) = 1
MonthMatrix(0, 1) = "Feb"
MonthMatrix(1, 1) = 2
MonthMatrix(0, 2) = "Mar"
MonthMatrix(1, 2) = 3
MonthMatrix(0, 3) = "Apr"
MonthMatrix(1, 3) = 4
MonthMatrix(0, 4) = "May"
MonthMatrix(1, 4) = 5
MonthMatrix(0, 5) = "Jun"
MonthMatrix(1, 5) = 6
MonthMatrix(0, 6) = "Jul"
MonthMatrix(1, 6) = 7
MonthMatrix(0, 7) = "Aug"
MonthMatrix(1, 7) = 8
MonthMatrix(0, 8) = "Sep"
MonthMatrix(1, 8) = 9
MonthMatrix(0, 9) = "Oct"
MonthMatrix(1, 9) = 10
MonthMatrix(0, 10) = "Nov"
MonthMatrix(1, 10) = 11
MonthMatrix(0, 11) = "Dec"
MonthMatrix(1, 11) = 12
month = "Sep"
month_number = Application.VLookup(month, MonthMatrix, 1, False)

这段代码有很多错误,很难一一列出。

  • Option Explicit必须在过程之外
  • 没有程序定义
  • 第一个Dim的左括号没有匹配的右括号
  • 矩阵设置为2行12列
  • 与Option Explicit,monthmonth_number需要定义
  • 你正在返回你正在查找的值

这是没有意义的。

最新更新