我正在尝试为Lookup_value左侧的一行获取Vlookup。 我无法Table_array"-1"(或-2),所以我想知道我是否可以在该代码行中执行偏移量(0,-1)。
有问题的台词:
wCell.FormulaR1C1 = "=VLOOKUP(RC[1],'[" & filename & "]" & ws.Name & "'!R8C4:R" & lastrow & "C5,-1,FALSE)"
整个代码块:
Range("$C$8:$C$" & lastrow).Select
For Each wCell In Range("$C$8:$C$" & lastrow)
wCell.Select
If wCell.FormulaR1C1 = "" Then
wCell.FormulaR1C1 = "=VLOOKUP(RC[1],'[" & filename & "]" & ws.Name & "'!R8C4:R" & lastrow & "C5,-1,FALSE)"
End If
Next
如果您想在Excel中查找参考点左侧的信息,则使用Match-Index
查找将是您的方式。这种方法不仅能够向参考的左侧或右侧查看,而且还是一个更快的过程。
VLookup 看起来像这样:
=VLookup([Value to find],[Where to find the value],[Column to return],[range lookup])
其中使用匹配索引如下所示:
=Index([Range to look in for return],Match([Value to find],[Range to look in for value],[Exact match or partial]))
因此,虽然编写起来有点复杂,但使用第二种方法确实增加了您可以查找的内容和信息位置的灵活性。
现在,如果要将此方法应用于代码,它应如下所示:
wCell.FormulaR1C1 = "=Index([Range of Value to Find],Match(RC[1],'[" & filename & "]" & ws.Name & "'!R8C4:R" & lastrow & "C5, [0 for exact match]))"
(只需更改我在括号中添加的位即可获得他们需要的信息,这应该可以解决您遇到的问题)