左右查找数据(有或没有 VBA)

look up data left and right (with or without VBA)

我有一个包含 2 个工作表的 excel 文件。

在名为 "data" 的第一个工作表中,我想从名为 "List" 的第二个工作表中查找数据。我需要查找的数据来自查找值的左侧和右侧。因此,我想知道您对同时从双方收集数据的最佳公式或代码的建议。

Worksheet 1 name "Data" > Value to look up is in "B7" is "John"

Worksheet 2 name "List" > Matching value to be looked up is in "D7" is "John"
                    > Return a value from "A7" -3 cells to the left
                    > Return a value from "G7" 3 cells to the right

有什么建议吗?

不确定您尝试了什么,

但我建议使用 .Find 然后向左和向右偏移。

例如:

Msgbox(工作表("List").Range("D1:D20").Find(工作表("Data").Range("D7").Value).Offset( 0,3). 值) Msgbox(工作表("List").Range("D1:D20").Find(工作表("Data").Range("D7").Value).Offset(0,-3) .值)

另一种选择是使用索引匹配,因此

=Index(List!A:A,Match(Data!B7,List!D:D,0),1) 它的左边

=Index(List!G:G,Match(Data!B7,List!D:D,0),1) 为它的右边

希望对您有所帮助