如何返回单元格公式的IF函数的初始值

时间:2019-11-08 21:07:39

标签: excel

我正在尝试构建一个包含长索引/匹配公式的IF语句。我希望IF语句返回如果逻辑测试为true时index / match语句发现的初始值。有没有办法解决这个问题而无需复制和粘贴公式?

import timeit

setups = """
list1 = [1,2]
list2 = [3,4]
list3 = list(range(5000))
list3 = list(range(5001))
list4 = list(range(20000))
listoflists1 = [list1,list2,list3]
listoflists2 = [list1,list2,list3,list4]
"""

test2= """
commons = set(listoflists2[0])
for l in listoflists2[1:]:
    commons = commons.intersection(l)
"""

result = timeit.timeit(setup=setups, number=5000, stmt="list(set.intersection(*(set(l) for l in listoflists1)))")
print("one liner with small exclusive lists and one large: %s" % result)
result = timeit.timeit(setup=setups, number=5000, stmt=test2)
print("loop with more large lists: %s" % result)
result = timeit.timeit(setup=setups, number=5000, stmt="list(set.intersection(*(set(l) for l in listoflists2)))")
print("one liner with more large lists: %s" % result)

因此,如果one liner with small exclusive lists and one large: 0.8411386758089066 loop with more large lists: 2.130048044025898 one liner with more large lists: 4.127526797354221 ,我想返回索引/匹配值。感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

考虑在单独的单元格中定义公式的索引/匹配部分:

=INDEX('2019'!$E$5:$BU$133, MATCH(Sheet1!$C$2 ...

然后可以在公式中引用它。因此,如果将上面的索引/匹配项放在单元格A1中,则可以通过以下方式引用它:

=IF(A1 > '2019'!E6, A1, ...

为减少混乱,可以将此类中间公式(如您的情况下的索引/匹配)放在隐藏的列中。