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

时间:2015-09-17 14:10:56

标签: excel vba excel-vba extract vlookup

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

我在Excel中有下表的值表:

      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

生成表格时,D列中的客户(以及其他列中的相应信息)以随机顺序出现。我想提取客户4的“总库存”数字。因此,我想在D列中搜索“客户4”,然后提取第一个“总库存”数字,该数字出现在Coloumn A之后。这一点。

我知道如何使用VBA进行VLookup并从B列中提取数字,但我不知道如何在每次表格更改客户的订单时确保提取正确的“总库存”数字是生成的。

任何建议都将不胜感激!

由于

1 个答案:

答案 0 :(得分:0)

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

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