【问题标题】:Find multiple values that match and return value from another column, in another workbook在另一个工作簿中查找多个匹配并从另一列返回值的值
【发布时间】:2015-04-10 17:38:17
【问题描述】:

我正在尝试在 VBA 中创建一个超级 VLOOKUP 函数,并且我已经让它在同一张表中正常工作,但我似乎无法弄清楚它是否可以在其他书籍中工作。

这个函数基本上接受三个参数:查找值、查找表和返回列。

查找值用于匹配查找表中的每个单元格,当找到匹配项时,它将从匹配单元格行的返回列中的单元格返回值。

这是我的代码:

Function SUPERLOOKUP(lv As Range, lt As Range, rc As Range)
Dim cell As Range
Dim output As String

For Each cell In lt
    If cell.Value = lv Then
        output = output & Range(ColumnLetter(uRC.Column) & cell.Row).Value & ", "
    End If
Next cell

SUPERLOOKUP = Left(output, Len(output) - 2)
End Function

ColumnLetter 是我用来将列号转换为其字母值的函数。

感谢任何帮助,甚至指出正确的方向。

【问题讨论】:

  • 用户返回列,这就是它之前的名称(我猜在那个代码中应该是 rc。

标签: excel vba lookup


【解决方案1】:

在这一行:

output = output & Range(ColumnLetter(uRC.Column) & cell.Row).Value & ", "

Range 将引用 ActiveSheet,因此您需要使用工作表引用对其进行限定。

例如(切换到Cells 以避免将列号转换为字母):

output = output & lt.Parent.Cells(cell.row, uRC.Column).Value & ", "

output = output & cell.EntireRow.Cells(uRC.Column).Value & ", "

【讨论】:

  • 谢谢蒂姆,很好的回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-13
  • 2022-11-18
  • 2023-01-19
  • 2021-09-19
  • 2018-11-26
相关资源
最近更新 更多