2016-06-17 9 views
0

私は条件付きマルチ連結を設定しようとしています。セル範囲の条件付き連結

原則は(SUMIFのように)1つの行/列に沿って実行し、値が条件に一致する場合は、合計範囲から対応する値を取り出して一緒に加算します。今回は、それらを連結しています(文字通り一緒に追加しています)。 この画像は、予想される結果と私の実際の結果を示しています。 Spreadsheet 私がいる問題は、それはまだ隙間なくカンマを与える最後のパラメータとして、どのようなI入力に関係なく(「#」を入力するにはまだコンマなどを与える)ことである...

ここでコードは次のとおりです。

/** 
 
* Concatenates a range of cells where the condition is met. 
 
* 
 
* @param {A4:A6} cRange The dynamic cell range to test. 
 
* @param {"Condition"} cCondition The string that the cell should match. 
 
* @param {A4:A6} pRange The dynamic cell range to concatenate. 
 
* @param {", "} interspace A string to insert between each entry. 
 
* @return The a concatenated range of cells 
 
* @customfunction 
 
*/ 
 
function conditionalMultiConcat(cRange, cCondition, pRange, interspace){ 
 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); //get the active workbook 
 
    var sheet = ss.getSheets()[0]; //get the active sheet 
 
    //var values = sheet.getRange(pRange).getValues(); //debug line - uncomment to see the values 
 
    var values = "" //set the return value to blank 
 
    for(var cc = 0; cc < pRange.length; ++cc) { //For each value in the array 
 
    if ((cc == 0 || cc == pRange.length - 1) && (cRange[cc] = cCondition)) { //if it's the first or last value AND it matches our condition 
 
     values = values + pRange[cc].toString();// concatenate without interspace 
 
    } 
 
    else if (cRange[cc] = cCondition){ //else if it matches our condition then concatenate with the interspace 
 
     values = values + interspace + pRange[cc].toString();// concatenate 
 
    } 
 
    } 
 
    return values; 
 
}

私はここで何をしないのですか?おかげさまで

答えて

1

私は式はあなたのためにこれを行うことができると思います。

=JOIN(",",FILTER(B1:D1,B2:D2="Y"))

+0

おかげで、これは動作し、私の方法よりもはるかに簡単です。私ができることならば、私のミスがコード内のどこにあるのか知ることも興味があるので、私は自分のgscriptingを改善することができます。 – Zaberi

関連する問題