简体   繁体   中英

use ISFORMULA with ARRAYFORMULA on a range of cells

I have a row of cells, some with a formula, and some without.

I am trying to use ARRAYFORMULA WITH IFFORMULA to see if a cell has a formula or not. This is the function I am using:

=ARRAYFORMULA(ISFORMULA(B2:B))

But it just outputs one single value.

在此处输入图像描述

There are other things I need to do for each row/cell which is why I need ARRAYFORMULA .

Is there another way to get ISFORMULA to work with ARRAYFORMULA ?

not all functions are convertible into ArrayFormula. ISFORMULA is one of those...

the best you can do is pre-program it like:

={ISFORMULA(B2);
  ISFORMULA(B3);
  ISFORMULA(B4);
  ISFORMULA(B5);
  ISFORMULA(B6)}

0


the next best thing you can do is to use conditional formatting to color it like:

green color:

=ISFORMULA($B2)

red color:

=NOT(ISFORMULA($B2))*(B2<>"")

0

This is so frustrating. I myself have made areFormula() by my needs. Not so elegant, but working. It takes a range of row or column (if area , treated as a row ), and returns a row.

function areFormula(rowOrColumn) {
  // takes a range as input parameter
  // from https://webapps.stackexchange.com/a/92156
  var sheet = SpreadsheetApp.getActiveSheet();
  var formula = SpreadsheetApp.getActiveRange().getFormula();
  var args = formula.match(/=\w+\((.*)\)/i)[1].split('!');
  try {
    if (args.length == 1) {
      var range = sheet.getRange(args[0]);
    }
    else {
      sheet = ss.getSheetByName(args[0].replace(/'/g, ''));
      range = sheet.getRange(args[1]);
    }
  }
  catch(e) {
    throw new Error(args.join('!') + ' is not a valid range');
  }
  rowOrColumn = range;

  //here starts my code
  let values = rowOrColumn.getValues();

  let isItRow = true;
  if(values.length == 1) {
    isItRow = false;
    values = values[0];
  }
  else {
    values = values.map(el => el[0]);
  }

  let result = [];
  let x = 0, y = 0;
  for(let i = 0; i < values.length; i++) {
    const cell = rowOrColumn.getCell(1+y, 1+x);
    result.push(cell.getFormula() ? true : false);

    if(isItRow) 
      y++;
    else 
      x++;
  }

  console.log(result);
  return(result);  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM