0

So I have got 3 sheets with 2 predefined ranges as you can see them in the Example:

# 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
...

Now I would like to have a Formular to get the wanted result I have been searching quite long time today already, but I wasn't successful. I hope there is anybody who may help me. I hope the example is clear enough to understand what i want to do.

Thanks in advance for your time.

1
  • 1
    Fine, edited the starting post. I do know this is a Q&A site, But I saw a lot of questions where exactly this is handled. Maybe because if you try to answer your own question you get a dialog. Changed it now and now I know how to handle such a situation for the next time. Commented Jan 23, 2015 at 14:35

1 Answer 1

1

I solved it in the end with google apps script. The function I used is pretty simple just two for loops:

/*
 * 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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.