OR Function of Excel with Error Values - excel-2010

I want to apply one OR Function in excel with some cells, but Excel is having #N/A(Error Value) in the containing cells, where i want to apply the formula.
Is it possible to apply OR Formula with the cells containing Error Values.
=OR((A1 = "T"),(B1 = "T"),(C1 = "T"))

You can use the IFERROR function (reference) to capture any errors in your source cells and replace them with a default value, say "F":
=OR((IFERROR(A1, "F") = "T"),(IFERROR(B1, "F") = "T"),(IFERROR(C1, "F") = "T"))

Related

How to subtract range from last non empty cell to first?

I am a beginner in google sheets and I couldn't get around this formula. I have range of cells and I want to subtract last non empty cell to first cell (Z-A), here is the image:
As the values are updated in columns C, D, E and so on. I want to get the last non empty cell (from right) and subtract the values by moving backward (left). Like this:
sub = 10(Column G)-0(Column F)-10(Column E)-0(Column D)-10(Column C)
Can we devise a formula which will get the last non empty cell and subtract values until the first value? Here is the link to the sample sheet Thank you
try:
=LOOKUP(1, INDEX(1/(C2:F2<>"")), C2:F2)-(SUM(C2:F2)-
LOOKUP(1, INDEX(1/(C2:F2<>"")), C2:F2))
Suggestion: Use a custom function
You may use the following script as a custom function to get the difference between the value of the last cell and the sum of the other cells:
function SUBTRACTFROMLASTNUMBER(data) { //you can rename the custom function name
var sum = 0;
var data2 = data[0].filter(x => {
return (x != "") ? x : null;
}); //filtered data
var lastNumber = data2.pop(); //last number
data2.map(x => sum += x); //sums the remaining values
return (lastNumber - sum); //returns the output
}
This custom function extracts the selected data from the sheet and then separates the value of the last cell using pop() and then filters and sums the remaining data using filter() and map() and then subtracts the sum from the value of the last cell.
Usage
You may use this function as:
=SUBTRACTFROMLASTNUMBER(<range>)
Reference:
How to Manipulate Arrays in JavaScript

Google Sheets: Tranfer(convert) a text of a formula from one cell to a proper formula in another cell - IDIRECT does not work

The question was raised several times with no result - INDIRECT does not work in this case.
In Excel EVALUATE function may help, but only using VBA, what also not very usefull.
Range A3:A6 contains conditions, Range B3:B6 - corresponding formulas's texts, E1 contains Condition Selector (Data Validation List in this case).
The formula in D9:D12: =indirect("B"&MATCH($E$1,A:A,1))
The question is - how to transfer(convert) the text from B3:B6 to D9:D12, to make them proper formulas?
Please, see a screenshot under this link:
converting text string into valid formula is possible only with script:
function onEdit() {
var sheet = SpreadsheetApp.getActive().getSheetByName("Contants"); // sheet name
var src = sheet.getRange("C2"); // The cell which holds the formula
var str = src.getValue();
var cell = sheet.getRange("C10"); // The cell where I want the results to be
cell.setFormula(str);
}
also keep in mind that your string needs to look exactly as formula with = sign in front. see: https://stackoverflow.com/a/60981768/5632629
Player0 - have my sincere thanks - it is really very simple, light and working solution. It works much better, than it made in Excel with it's Evaluate() function.
My final code for my particular example was the following:
function onEdit() {
var sheet = SpreadsheetApp.getActive().getSheetByName("Sample"); //
sheet name
var rowNoCell = sheet.getRange("F1");
var rowNo = rowNoCell.getValue();
var src = sheet.getRange("B"+rowNo); // The cell which holds the formula
var str = src.getValue();
var cell = sheet.getRange("D9:D12"); // The cell where I want the r
esults to be
cell.setFormula(str);
}
It takes corresponded to Condition, selected in F1, cell in the range B3:B6 and post the formula to the range D9:D12.
F1 contains =MATCH($E$1,A:A,1) to link the condition in F1 with values in A3:A6
The only thing that the formula in B3:B6 range has to be a string, without "=" in front.
Thanks a lot once again - the problem solved!
Screenshot

Multiply select value from QUERY

I have created a named range called coins and have the following query:
=QUERY(coins,"SELECT C WHERE A = '"&B17&"' ")
which returns the correct values. If I want to multiply this number by e.g. 2 and write the following:
=QUERY(coins,"SELECT C*2 WHERE A = '"&B17&"' ")
my cell is replaced with product(2()) and the correct value is placed at the underneath cell.
I have tried also:
=QUERY(coins,"SELECT product(C,2) WHERE A = '"&B17&"' ")
but had no correct result.
How do I get the value of the multiplication on that specific cell and not the one underneath?
try like this:
=QUERY(coins, "SELECT C*2 WHERE A = '"&B17&"' label C*2''")

How to conditional format merged and regular cells

I have a google sheet that I want to add a conditional formatting, but the merged cells kinda of get in the way.
In my spreadsheet, I have the columns B,C,D and E where i'm using a formula in column B for when columns C,D and E are "done" column B gets a green background. The problem is, for some rows, columns D and E are merged.
This is the formula I'm using in column B
=and(C:C="done",D:D="done")
My desired result is: When the columns D and E are not merged, column B only gets the green background if columns C,D and E are "done", or else, it stays blank.
When D and E are Merged : B only gets green background if C and DE are "done", or else, stays blank.
Thanks in advance!!
If E always has a non-empty value when D and E aren't merged, you can use that to check for when E is blank using ISBLANK(E:E):
=AND(C:C="done", D:D="done", OR(E:E="done", ISBLANK(E:E)))
Otherwise, there isn't a way to test if a cell is part of a merged range without using a custom function, which is far less efficient, but could technically work with the assistance of a new helper column (e.g. column Z):
/**
* #customfunction
*/
function ISMERGED(cellAddress) {
var cell = SpreadsheetApp.getActiveSheet().getRange(cellAddress);
return cell.isPartOfMerge();
}
Where column Z (or whatever you choose for your helper) has the following in every relevant row (assuming data starts in row 1):
=ISMERGED(ADDRESS(ROW(E1), COLUMN(E1)))
=ISMERGED(ADDRESS(ROW(E2), COLUMN(E2)))
=ISMERGED(ADDRESS(ROW(E3), COLUMN(E3)))
...and so on.
And then for formatting B, use:
=AND(C:C="done", D:D="done", OR(E:E="done", $Z:$Z))
WARNING: If you toggle between merging and unmerging, Z wont contain the correct values immediately, though, because custom functions only re-compute when input changes (and the address of the cell wont in this case).
Update
Here's how you could compute your helper for the whole column downward, by row, by just putting the value in the topmost cell (ex: =ISMERGED("E:E") in cell Z1):
/**
* #customfunction
*/
function ISMERGED(rangeAddress) {
var range = SpreadsheetApp.getActiveSheet().getRange(rangeAddress);
var numCols = range.getNumColumns();
var numRows = range.getNumRows();
var result = [];
for (var i=0; i < numRows; i++) {
var rowRange = range.offset(i, 0, 1, numCols);
result.push(rowRange.isPartOfMerge());
}
return result;
}
best you can get is:
=OR(AND(C:C="done", D:D="done", E:E="done"),
AND(C:C="done", D:D="done", ISBLANK(E:E)))
which will work unless 4th row:
but you could pre-populate the whole E column with =CHAR(1) and then:

send email on a change in a cell value with message from another cell

I am new to google scripts. I have a range where the cells in a column change. If the number of a cell from that column is above zero then the script has to send an email with the message being the content from a cell in the same row with the updated cell(that is, different column) Let's say If a value in column I changes then automatically it has to send an email with the message contained in the same row but column F for example. Please see below, I would appreciate some help.
function SendValue() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Dividend");
var values = sheet.getRange("I2:I").getValues();
//var values1 = sheet.getRange("G2:G").getValues();
var results = [];
for(var i=0;i<values.length;i++){
if(values[i]>0){
results.push(sheet.getIndex([+i+2]+"G"));
// +2 because the loop start at zero and first line is the second one (I2)
}
}
MailApp.sendEmail('sxxxxxx#gmail.com', 'EX-DIVIDEND', results );
};
getValues() returns a 2 dimensional array, or more accurately an array of arrays, even if one of the dimensions is 1. values[i] is not a value but rather an array representing the i row of the range. You will need to acess that array to get at the cell at a particular column in that row.
replace if(values[i]>0) with if(values[i][0]>0)
I suspect that results.push(sheet.getIndex([+i+2]+"G")); should be results.push(sheet.getRange("G"+(i+2)).getValue()); as getIndex() doesn't take arguments and that looks like it is meant to be A1 notation.
However there is a better option than trying to construct A1Notation.
getRange() supports using numbers to refer to rows and columns. getRange(7, i+2) is a better choice.
https://developers.google.com/apps-script/reference/spreadsheet/range#getvalues
https://developers.google.com/apps-script/reference/spreadsheet/sheet#getRange(Integer,Integer)

Resources