Excel VBA - 在另一个值之后查找值的第一个实例

Excel VBA - Find first instance of value after another value

创建该示例是为了帮助说明我的问题。

我在 Excel 中有 table 个值 table:

      A                 B         C         D 
Total Inventory      £55,000            Customer 3
Work In Progress     £20,000
Completed Goods      £35,000

Total Inventory      £60,000            Customer 4
Work In Progress     £30,000
Completed Goods      £30,000

Total Inventory      £20,000            Customer 2
Work In Progress     £5,000
Completed Goods      £15,000

Total Inventory      £2000              Customer 1
Work In Progress     £1500
Completed Goods      £500

当生成 table 时,D 列中的客户(以及其他列中的相应信息)以随机顺序出现。我想提取客户 4 的 "Total Inventory" 数字。因此,我正在寻找一种在 D 列中搜索 "Customer 4" 的方法,然后提取出现在中的第一个 "Total Inventory" 数字之后是A栏。

我知道如何使用 VBA 进行 VLookup 并从 B 列中提取图形,但我不知道如何确保在顺序为 "Total Inventory" 时提取正确的图形每次生成 table 时,客户都会发生变化。

如有任何建议,我们将不胜感激!

谢谢

Sub Macro1()

Dim cust As String

cust = "Customer 3" ' it can be any other varible I just used this to check the data


formu = "index(b:b,match(""" & cust & "Total Inventory"",c:c&a:a,0),1)" ' this one will run to lookups and make sure that correct line with 2 lookup values
Result = Evaluate(formu)
MsgBox (Result) ' again I entered this just to see that this is working


End Sub

内联文本。经过测试和验证。