【问题标题】:Excel: How to find the last matching value in your table, prior to the active cellExcel:如何在活动单元格之前找到表格中的最后一个匹配值
【发布时间】:2022-11-08 21:04:48
【问题描述】:

我想找到与当前表行中的值匹配的最后一个条目。 IE。

ID Name Surname Current Salary old Salary
1 Lisa Smith 10000
2 Thomas Phu 5000
3 Lisa Franklin 90000
3 Lisa Smith 20000 10000 (Gets value from first entry, matched by name and Surname)

在那种情况下,我希望“旧薪水”引用与名称“丽莎”和姓氏“史密斯”匹配的第一个条目 ID 1 的“当前薪水”值。

有没有人有好的方法? Rn 我有点不知所措

我在网上找到了这段代码,这几乎是我的用例,但不完全是。 知道如何为我的用例修改它吗?

Function ItemLookup(Lookupvalue As String, LookupRange As Range, ColumnNumber As Integer)
Dim i As Long
For i = LookupRange.Columns(1).Cells.Count To 1 Step -1
If Lookupvalue = LookupRange.Cells(i, 1) Then
ItemLookup = LookupRange.Cells(i, ColumnNumber)
Exit Function
End If
Next i
End Function

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    不需要任何 VBA 代码来完成您正在寻找的内容。

    在您的“旧工资”列中,您需要一个索引匹配公式。 如果您想通过“姓名和姓氏”匹配此数据,则需要一列用于此类数据。这可以通过像 =B2&C2 或 =B2&" "&C2 这样的公式来完成。 可以隐藏此类公式的列。

    然后,您需要在此列上使用索引匹配。 你想找到最后出现的数据集。 阅读此处了解如何找到第 n 次出现:https://exceljet.net/formulas/get-nth-match-with-index-match

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-28
      相关资源
      最近更新 更多