How to not count cells across sheets which do not contain text? - google-sheets

Currently I have a formula which calculates the text contained within a given cell across multiple sheets i.e.:
=COUNTIF(Sheet1!G3:G1151, "COMPLETE") + COUNTIF(Sheet2!G3:G1151, "COMPLETE")
I need to not calculate (Count) a cell if it does not contain text, i.e.:
=COUNTIF(Sheet1!G3:G1151, "COMPLETE") + COUNTIF(Sheet2!G3:G1151, "COMPLETE") + !COUNTIF(Sheet2!G3:G1151, "COMPLETE")
Any ideas? thanks

Not is <>:
=COUNTIF(Sheet1!G3:G1151, "<>COMPLETE") + COUNTIF(Sheet2!G3:G1151, "<>COMPLETE") + COUNTIF(Sheet2!G3:G1151, "<>COMPLETE")

Related

Merge all cells to one cell and separate with comma

I use Google Sheets, and I want to get data and create one new cell.
Example:
I have 300 rows and 4 columns, like:
1|3|2|4
5|7|6|8
9|11|10|12
...
297|299|298|300
and one cell that I need in result:
1,3,2,4,5,7,6,8,9,11,10,12...297,299,298,300
=SUBSTITUTE(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(A2:D),,999^99)),,999^99)), " ", ", ")
______________________________________________________
but if you want just numbers from 1 - 300 in CSV then:
=ARRAYFORMULA(JOIN(", ", ROW(A1:A300)))
You could use Textjoin:
=TEXTJOIN(",",1,A2:D)

Check if each cell range in a row contains the same value

How can I check in Google Sheets if each cell in a range e.g. B2:G2 contains a word e.g. holiday?
=ARRAYFORMULA(IF(IFERROR(REGEXEXTRACT(B2:G2, "holiday"))<>"", TRUE))
=ARRAYFORMULA(IF(SUM(IF(IFERROR(REGEXEXTRACT(B3:G3, "holiday"))<>"", 1))=6, TRUE))

Conditional formatting for alternating groups of duplicated cells

I am trying to get a conditional formatting formula that highlights groups of duplicated cells in a column, but that also differentiates among them.
When I use the formula =COUNTIF($J:$J,J1)>1, I get:
123 (green)
123 (green)
345
567
765 (green)
765 (green)
812 (green)
812 (green)
876
But I want something more like:
123 (green)
123 (green)
345
567
765 (yellow)
765 (yellow)
812 (red) (or green again)
812 (red) (or green again)
876
I don’t necessarily need different colors for each group (although that would be really nice), but at least two colors that alternate between the groups, so I can't easily visually differentiate between two adjacent group of duplicated cells.
For that last part, I am working with the formula =isodd(match($J2,unique($J$2:$J))) (plus one with iseven to use it with another color), the problem with this one is that it also highlights unique cells (which I don’t want).
Is there is a way to combine the two or another formula altogether that accomplish this?
Add this script and your sheet will highlight duplicated rows.
It automatically updates every time you edit the sheet.
So you can insert rows, or add rows or change rows and it will still update correctly.
You can look up how to install the script, but its easy. Let me know if stuck.
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var lastRow = sheet.getLastRow();
var range = sheet.getRange(1,1,lastRow);
sheet.getRange("A1:A").setBackground("white");
var rowValues = range.getValues();
var color1 = "#DBAB30"; // light yellow
var color2= "#3DA843"; // light green
var color = color1;
if (lastRow < 2) return; // do nothing if only 1 row.
var dupCount=0;
var row;
for (row=1; row<=lastRow; row++)
{
if (row == lastRow){ // check if past the last row.
applyBackground(row-1,dupCount);
}
else{
if (rowValues[row][0] == rowValues[row-1][0])
{
dupCount++;
}
else
{
applyBackground(row-1,dupCount);
dupCount=0;
}
} // end if not last row
} // end loop
function applyBackground(row,dupCount){
if (dupCount > 0)
{
var colorRange = sheet.getRange(row-dupCount+1,1,dupCount+1);
colorRange.setBackground(color);
if (color == color1) {color = color2} else {color=color1};
}
}
}
Produces this output:
Which I think is what you asked for?
This isn't quite what you're looking for, but you can apply this formula starting in row 2 to identify the odd groups:
=and(or(A2=A1,A2=A3),isodd(sumproduct((A$1:A1<>A$2:A2)*(A$2:A2=A$3:A3))))
and similarly for the even groups:
=and(or(A2=A1,A2=A3),iseven(sumproduct((A$1:A1<>A$2:A2)*(A$2:A2=A$3:A3))))
If you tried to apply this to row 1, you would get a #REF! error. The only way I could come up with to identify a repeated value starting in row 1 was to add a third rule applied to the whole range:
=and(A$1=A$2,countif(A$1:A1,"<>"&A1)=0)
and to modify the original formulas to
=and(or(A2=A1,A2=A3),isodd(sumproduct((A$1:A1<>A$2:A2)*(A$2:A2=A$3:A3))+(A$1=A$2)))
and
=and(or(A2=A1,A2=A3),iseven(sumproduct((A$1:A1<>A$2:A2)*(A$2:A2=A$3:A3))+(A$1=A$2)))

Can you count links within a range?

I have many Google sheets that require manually hyperlinking (to specific unique documents) after other users have inserted values, but it is time-consuming to search through many sheets for cells yet to be linked. A basic solution would be to use COUNTA to get the number of cells within a range containing text, and a second function to count the number of links, showing the difference. I've tried many permutations of COUNTA and COUNTIF using wildcards but nothing seems to be able to recognise formulas. Is there a function within Google Sheets of getting the number of hyperlinked cells within a range?
If you are referring to urls in cells (like: www.google.com), you can try:
=SUM(ArrayFormula(N(ISURL(A3:A))))
Change range to suit.
This will not work if you are using =HYPERLINK() function.
EDIT: If you want to count the cells with text, but exclude the =Hyperlink() formulas (AND empty cells) you can try this custom function:
function countF(range) {
var r = SpreadsheetApp.getActive().getRange(range),
formulas = r.getFormulas(),
count = 0;
r.getValues()
.forEach(function (r, i) {
r.forEach(function (c, j) {
if (c && formulas[i][j].substring(1, 10) !== "HYPERLINK") count += 1;
})
})
return count;
}
This custom function can be used in your spreadsheet by entering
=COUNTCELLS("Sheet1!A1:A2")
If you want to exclude all formulas from your count, change the if-statement to:
if (c && !formulas[i][j]) count +=1
Make sure you always mention the sheet name.
EDIT2: to count the number of formulas, you can try something like this:
function countFormulas(range) {
var count = 0;
SpreadsheetApp.getActive()
.getRange(range).getFormulas()
.forEach(function(r) {
r.forEach(function(c) {
if (c.charAt(0) == '=') count += 1;
})
})
return count;
}
I suggest the following. The formula assumes the cells to check for Hyperlinks are in column A with header (adjust formula to your need). Select A2. Right click and select Conditional Formatting. Enter the following:
Apply to range
A2:A
Format cells if
Choose 'Custom formula is' from dropdown list and enter:
=AND(NOT(ISFORMULA(A2)),NOT(ISBLANK(A2)))
Choose the formatting style you want.
This will format and non blank cell not containing a formula. (No Hyperlink)
Two other options to get just a count:
In a column, lets say B enter the following formula(Note that ISFORMULA does not work in array formulas like ISBLANK does.) Copy the formula down. It will return FALSE if there is a Hyperlink and TRUE if there is not.
=NOT(ISFORMULA(A2))
Then to count use:
=countifs(B2:B,"TRUE",B2:B,"<>''")
The other option is script:
function noFormula() {
var ss=SpreadsheetApp.getActiveSpreadsheet()
var s = ss.getSheets()[0];// [0] is Sheet1
var lr=s.getLastRow()
var rng =s.getRange(2, 1, lr-1, 1) //get column A data. Assumes header row.
var data=rng.getFormulas()
count=0
for(i=0;i<data.length;i++){
var hasFormula=data[i][0]
var eqSign=hasFormula.substring(0,1) //looks for first character "=". If there are formulas other than Hyperlinks change to substring(0,2) to look for "=H".
if(eqSign !="="){ //Not equal to"="
count = count+1
}}
var c=s.getRange(1,2).setValue(count)//Sheet1 B1
}

Highlight Row if Value in Column is above 0 - Google Spreadsheet

I am trying to get a Google spreadsheet to automatically highlight all rows in a spreadsheet where the value in a particular column is above 0. I have looked for a few solutions but haven't got it to work.
I have got various metrics in the columns, so say I want to highlight all rows, in which column "I" has a value of more than zero.
Can someone help me with this?
On the conditional formatting page choose "Custom formula is" from the list of options available and then in the text field type:
=$I:$I>0
Select your formatting options and then in the range field type the range. For example:
A2:Z100
Because only to be applied to a single column there is a simpler version (that I have complicated so that text is not highlighted):
Clear formatting, select ColumnI and Format, Conditional formatting..., Format cells if... Custom formula is and:
=and(isnumber(I1),I1>0)
with fill of choice and Done.
If to format not just the relevant cell but the entire row then change the Apply to Range (say to A1:Z1000) and add anchors ($s) as below:
=and(isnumber($I1),$I1>0)
The only solution I'm aware of would be to write a script.
Link: Google Apps Scripts
The following is not pretty, but it works:
function myFunction() {
var I_INDEX = 1;
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Highlight rows");
var dataRange = sheet.getDataRange();
var dataValues = dataRange.getValues();
for (var i=1; i<=dataRange.getNumRows(); i++) {
var row = sheet.getRange(i, 1, 1, 2);
if (dataValues[i-1][I_INDEX] > 0) {
row.setBackground("red");
}
}
}
See example, use "Tools" --> "Script Editor..." to view/run the script.

Resources