修复:检查user3964075的评论
下面我的简单代码需要帮助:它基本上是 vlookup 的不同版本,您还可以在其中指定要查找的行。
asda(fval, rng, fcol, rcol)
fval是用户正在寻找的
rng是范围
fcol是 vlookup 默认的,设置为 1,现在用户可以选择使用哪一列作为搜索的基础
rcol是找到匹配项时返回的列
请参见下面的代码:
Function asda(fval As Range, rng As Range, fCol As Integer, rCol As Integer)
Dim row As Variant
For Each row In rng.Rows
If fval.Value = rng.Columns(fCol).Rows(row).Value Then
result = rng.Columns(rCol).Rows(row).Value
GoTo found
End If
Next
found:
asda = result
End Function
问题:它不起作用,我不知道为什么。由于我想使用其他人的代码,我想从我的开始并修复它。
为将来阅读此内容的任何人修复了代码:
Function asda(fval As Range, rng As Range, fCol As Integer, rCol As Integer)
Dim row As Variant
Dim rowc As Integer
rowc = 1
For Each row In rng.Rows
If fval.Value = rng.Cells(rowc, fCol).Value Then
result = rng.Cells(rowc, rCol).Value
Exit For
End If
rowc = rowc + 1
Next
asda= result
结束功能