我在VBA中遇到以下Index/Match
公式时遇到问题。
以下是代码
Sub MSTitl_box()
Dim Target As Range
Dim x As Variant
Dim y As Variant
Dim z As Variant
Dim refdate As Variant
Dim discat As Variant
Dim Milestone As Variant
Dim criteria As Variant
Set Target = ActiveSheet.Range(ActiveCell.Address)
x = Target.Column - 2
y = Target.Row - 2
refdate = Application.WorksheetFunction.Index(Range("C2:AF2"), x)
discat = Application.WorksheetFunction.Index(Range("B3:B23"), y)
z = discat & refdate
criteria = Formula = "=MATCH(" & z & ",msrng,0)"
Milestone = Formula = "=INDEX(colm_mstitle_rng," & criteria & ",0)"
MsgBox criteria
End Sub
变量refdate
是日期值,格式为“m / d / yyyy”& discat
是一个文本字符串。
z
显示x&的正确连接值年。但是当它转到MATCH公式时,它表示FALSE,随后索引公式失败。
我认为它与变量定义有关。