[英]Why does VLookUp keep returning Error 2042?
Probably that´s not the smartest way to convert "Jan" to "1" from a date like Jan 01, 2021", but why does VLookUp keep returning Error 2042?可能这不是从 2021 年 1 月 1 日这样的日期将“Jan”转换为“1”的最聪明方法,但为什么 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)
There are so many things wrong with this code that it's hard to list them all.这段代码有很多问题,很难一一列举。
month
and month_number
need to be defined使用Option Explicit,需要定义month
和month_number
This just doesn't make sense.这只是没有意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.