繁体   English   中英

excel在多个列中查找

[英]excel lookup within multiple columns

我希望有人可以帮助我完成一个简单的任务。

我有一个工作表(Sheet1),其中有许多列。 前两个分别是数字和名称。 在这两列之后,每一行都有许多列(例如,第一行有10个列,第二行有4列,等等)。

我有另一个工作表(Sheet2)2列。 第一列具有我要在Sheet1中查找的值。 问题是该值可以在前两列之后的Sheet2的列中的任何位置。(例如,查找值123,值在第13列第6行或查找值456在第5列第14行),然后我想要在Sheet1上的第1列第6行要放入Sheet2的第2列。

我曾尝试使用Vlookup,Hlookup和Lookup,但似乎无法弄清楚如何使其工作。

任何帮助将非常感激

谢谢加雷斯

...我知道您并没有要求VBA解决方案,但我只是想写一个,看看我将如何做...

我使它“快速又脏”,没有任何错误检查等,但是它将为您提供所需的内容:

  Public Function FindInRange(Val As Variant, LookIn As Range, ColIndexNumber As Integer) As Range

  ' INPUTS:
     ' Val             = The Value you're looking for in your Range of cells
     ' Range           = The range of cells you're searching through
     ' ColIndexNumber  = The index of the column you want a value returned from within the row from which the value is found

  ' NOTE:
  ' This will only pull the first value matching your "Val" argument

  Dim FoundCell As Range

  Set FoundCell = LookIn.Find(what:=Val, LookAt:=xlWhole)

  If FoundCell Is Nothing Then
     Set FindInRange = Nothing
  Else
     Set FindInRange = Intersect(LookIn.Columns(ColIndexNumber), FoundCell.EntireRow)
  End If

  End Function

如果将其粘贴到VBA模块中,则可以像此时的其他任何函数一样从电子表格中调用它。

希望这可以帮助 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM