使用查找或macros在Excel中从表中获取价格

我在下面的结构excel表中有“PriceList”表

Type Thickness width Height Price iron 5 7 10 20 iron 10 10 15 24 iron 12 14 17 26 

我怎么能find价格,如果某人进入types铁,厚度10,宽度9,高度14使用vlookup或macros。 我曾尝试使用vlookup,但它不工作,后来我发现在谷歌,Vlookup只能检索一个参数的数据。 我可以像使用macros一样使用查询来select图表数据吗?

 select * from [sheet1$] where col1=x 

请build议?

编辑:我已经使用此计算上述。 现在我在下面的换页事件上调用这个macros

  Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 41 Or Target.Column = 43 Or Target.Column = 45 Or Target.Column = 46 Then Dim i As Currency i = Calculate_CorePrice(cell(Target.Row, 46).Value, cell(Target.Row, 45).Value, cell(Target.Row, 41).Value, cell(Target.Row, 43).Value, "RWJ Doorset Schedule", "ED15") cell(Target.Row, 134).Value = i End If End Sub 

如果我使用硬编码值debugging函数本身,它正在工作,但如果我以上述方式调用函数,它不会返回值,我不能debuggingsheet_change事件。

我怎样才能debugging这个事件。

假设您的列是A,B,C等。您可以使用索引/匹配公式作为数组(使用CTRL + SHIFT + ENTERinput )。

如果用户在W1X1Y1Z1inputtypes,厚度,宽度和高度,则可以使用:

=Index($E$2:$E$10,Match(W1&X1&Y1&Z1,$A$2:$A$10&$B$2:$B$10&$C$2:$C$10&$D$2:$D$10,0))

这很复杂,但基本上Match部分是你正在寻找范围A2:A10 W1 ,然后无论是在X1 ,你会searchB2:B10 ,等等。

我的答案似乎迟了一点,@BruceWayne打我。 不过,我会添加我的解决scheme以及有一个很好的小插图:

在这里输入图像说明

基本上,已经提出了同样的build议。 只需使用数组公式和&符号将所有条件合并为一个。 最后一个标准将看起来像这个iron101015 (例如)。 并将它与表格中的所有组合进行比较。

最好的方式是循环访问数据,使用if语句来检查数据表。 (根据您希望如何检索数据,这可以放在一个子函数或一个函数中)

 Function GetPrice(Type As String, Thickness As Integer, Width As Integer, Height As Integer) Dim ItemRow As Range, SearchColumn As Range 'Dim Price As Double 'Use variable if this were a sub Set SearchColumn = Range(Cells(2,1),Cells(ActiveSheet.UsedRange.rows.count,1)) For Each ItemRow In SearchColumn If ItemRow.Value = Type AND ItemRow.Offset(0,1).Value >= Thickness AND ItemRow.Offset(0,2).Value >= Width AND ItemRow.Offset(0,3).Value >= Height AND ItemRow.Offset(-1,1).Value < Thickness AND ItemRow.Offset(-1,2).Value < Width AND ItemRow.Offset(-1,3).Value < Height Then 'Price = ItemRow.Offset(0,4).Value GetPrice = ItemRow.Offset(0,4).Value Exit For End If Next ItemRow End Function 

编辑:鉴于您对另一个答案的评论,我调整了代码,以find值,因为我相信你正在寻找