首页 > 解决方案 > 编码索引匹配以搜索多个列

问题描述

我需要在多列中搜索一个数字,然后在另一个单元格中返回信息。这是一个示例表:

样品表。

我想保留左边的名字和顶部的会议。其他名称和会议将在以后添加。

在单独的选项卡上,我使用以下功能:

=SMALL('100M'!B2:D5,1)

找出表格中最小的数字。我现在需要在表格中搜索上述函数的结果并返回此人的姓名。我知道索引/匹配:

=index('100M'!$A$2:$D$5,match($B$2,'100M'!$D$2:$D$5,0),1) 

如果我指定确切的列,这将起作用。我需要搜索每一列以匹配小号,然后返回个人姓名。

标签: google-sheetsexcel-formula

解决方案


创建用户定义函数

Function GetMinName() As String

    Dim dataRange As Range
    Dim minValue As Double
    Dim minValueCell As Range
    
    ' Define the data range
    Set dataRange = Worksheets("Sheet1").Range("B2:D5")
        
    ' Find the minimum value in the data range
    minValue = WorksheetFunction.min(dataRange)
        
    ' Find the first cell containing minimum value
    Set minValueCell = dataRange.Find(minValue, LookIn:=xlValues)
    
    ' Return the name in col 1 of the row containing the min value.
    GetMinName = Worksheets("Sheet1").Cells(minValueCell.Row, 1)

End Function

这是您在另一张纸上的单元格中输入的公式。

=GetMinName()

推荐阅读