作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想为以下 Excel 索引匹配公式创建一个 UDF:
{=INDEX($A$1:$J$7,MATCH(B9,$A$1:$A$7,0),MATCH(1,($A$1:$J$1=B10)*($A$2:$J$2=B11),0))}
AA AA AA BB BB BB CC CC CC
a b c a b c a b c
1 10 55 24 48 95 19 5 28 65
2 16 48 3 62 46 50 59 80 17
3 63 47 19 23 67 26 14 16 9
4 55 91 4 55 72 79 27 39 50
5 75 53 7 42 45 19 58 41 12
Condition1 3
Condition2 AA
Condition3 c
index-Match 19 =INDEX($A$1:$J$7,MATCH(B9,$A$1:$A$7,0),MATCH(1,($A$1:$J$1=B10)*($A$2:$J$2=B11),0))}
CTRL + SHIFT + ENTER
在excel中返回数组结果
Public Function UDF_IndexMatch(Condition1, Condition2, COndition3)
UDF_IndexMatch = Application.WorksheetFunction.Index(Range("$A$1:$J$7"), _
Application.WorksheetFunction.Match(Condition1, Range("$A$1:$A$7"), 0), _
Application.WorksheetFunction.Match(1, (Range("$A$1:$J$1") = Condition2) * (Range("$A$2:$J$2") = COndition3), 0))
End Function
= UDF_IndexMatch(Condition1, Condition2, COndition3)
最佳答案
起初我误读了您的帖子,并认为使用标准公式会更好,但是您正在专门寻找 UDF。只是为了提供其他选择,这里有一个:
Public Function ReturnVal(RNG As Range, Con1, Con2, Con3) As String
Dim SearchRng1 As String, SearchRng2 As String, SearchRng3 As String, SearchRng4 As String
With ActiveWorkbook.Sheets(RNG.Parent.Name)
SearchRng1 = RNG.Parent.Name & "!" & RNG.Range(.Cells(3, 2), .Cells(RNG.Rows.Count, RNG.Columns.Count)).Address(False, False)
SearchRng2 = RNG.Parent.Name & "!" & RNG.Range(.Cells(3, 1), .Cells(RNG.Rows.Count, 1)).Address(False, False)
SearchRng3 = RNG.Parent.Name & "!" & RNG.Range(.Cells(1, 2), .Cells(1, RNG.Columns.Count)).Address(False, False)
SearchRng4 = RNG.Parent.Name & "!" & RNG.Range(.Cells(2, 2), .Cells(2, RNG.Columns.Count)).Address(False, False)
End With
ReturnVal = Evaluate("=INDEX(" & SearchRng1 & ",MATCH(" & Con1 & "," & SearchRng2 & ",0),MATCH(""" & Con2 & """&""" & Con3 & """," & SearchRng3 & "&" & SearchRng4 & ",0))")
End Function
关于excel - 如何为多变量索引匹配公式创建 UDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55711753/
我是一名优秀的程序员,十分优秀!