为每个单元格创建具有多个答案的查询

Create query with multiple answers for each cell

所以我有 3 个工作表和 2 个预定义范围,您可以在示例中看到它们:

# RangeA    # RangeB    # Wanted Result
========    ========    ===============
A | B       A           A
--------    --------    ---------------
1 | a       a           a
2 | a       b           1
3 | a                   2
4 | b                   3
5 | b                   b
6 | b                   4
7 | c                   5
8 | c                   6
9 | c
...

现在我想要一个公式来获得我今天已经搜索了很长时间的想要的结果,但我没有成功。我希望有人可以帮助我。 我希望这个例子足够清楚,可以理解我想做什么。

提前感谢您的宝贵时间。

最后我用 google 应用程序脚本解决了它。 我使用的函数非常简单,只有两个 for 循环:

/*
 * Merge merges two arrays to get one list of wanted values
 * @param needle {array} is a list of wanted values
 * @param haystack {array} is a list of values and their group
 * @return returns a list of merged values in the format group, value,
 *         value, group ...
 **/
function Merge(needle, haystack) {
  var result = [];
  // Set default values to parameters if parameter is not set.
  needle = needle || [[]];
  haystack = haystack || [[]];
  // Filter the array and remove empty items. # RangeB
  needle = needle.filter(function(item){
    return item[0];
  });
  // Filter the second array and remove empty or incomplete items # RangeA
  haystack = haystack.filter(function(item){
    return item[0] && item[1];
  });
  // Merge both arrays to get the # Wanted Result
  needle.forEach(function(item){
    result.push([item[0]]);
    haystack.forEach(function(needle){
      if(item[0] == needle[1]) {
        result.push([needle[0]]);
      }
    });
  });
  // Check if the result has a length
  if(result.length > 0) {
    return result;
  }
  // else return null to overcome the #error message
  return null;
}