Conditional formatting not working with 'countif' function in Google Sheets - google-sheets

I'm trying to apply a simple custom formula in a conditional formatting rule in Google Sheets, but it's not working for me and I can't understand why.
I have two sheets. The first sheet contains a series of rows, that start with an id:
ID
50013 50 13 Member of the City Council 3 4
50082 50 82 Member of the City Council 3 62
50083 50 83 Member of the City Council 3 130
Then my second sheet contains another similar list of rows, which is a subset of those in the first sheet. What I'm trying to do is highlight the rows in the first sheet where the "ID" field (indicated above) is in the subset in the second sheet.
The rule I'm tryin to use is:
countif('Bernie Intersect 1'!$A$2:$A$22, A2)
But when I put it into the conditional formatting conditional field, I don't get the desired result. I can't see the output, but evidently the field is not coming back with TRUE...
I thought that I might need an = in front of the expression, but if I add that I get an error that the formula is invalid.
Does anyone know what I might be doing wrong here?

Conditional formatting formulas do not allow explicit references to other sheets. Use indirect to get around this restriction:
=countif(indirect("'Bernie Intersect 1'!A2:A22"), $A2)
With indirect there is no need to say that A2:A22 are absolute references, since they are in the string format anyway; within indirect everything is absolute.

Related

Sheets conditional formatting if contains text from another cell

I have a Google sheet which has a column for business name (A) and a column for city (B). I would like to set conditional formatting such that if the city name is contained within the business name on the same row, the business name will be highlighted.
list example
Every row contains different business/city data, and there are thousands of rows. I need one formula that will work for the whole sheet.
I know how to do it if the city name and business name are exactly the same =$A$2:$A=$B2, but struggling to figure out how to do it if just a portion matches. Putting an asterisk before $B2 broke the formula.
=REGEXMATCH ($A2,$B2) would do the work too!
Use SEARCH:
=AND(ISNUMBER(SEARCH(TRIM(B2),A2)),B2<>"")
with range starting from A2. You search if A2 contains text from B2 and returns starting number if found. So if it is a number then ISNUMBER returns TRUE
Result:

Combining a Cell Reference and Wildcard as Criterion in Google Sheets CountIf Formula

I'm struggling with writing the proper syntax for this formula in Google Sheets. In one sheet called Game Log, in the H column I have data that can be a range of names (1 - 10 names per row). I'm trying to construct a COUNTIF statement that would search for the name in all the rows for that column. There can be several other names in the same column so I need to use the wildcard * to find any occurrence of the name in each row. So for example, the current code below would count all occurrence of Adam in the rows.
=COUNTIF('Game Log'!H3:H102, "*Adam*")
What I would like to do is replace the hard codes "Adam" with a cell reference (in this case B2). Is it possible to combine that cell reference with the wild card? The know the code below doesn't work (as it would return text counting occurrences of B2), but is something like this possible?
=COUNTIF('Game Log'!H3:H102, "*B2*")
Have you tried something like this?
=COUNTIF('Game Log'!H3:H102, "*" & B2 & "*")
That ought to look for any string value, followed by the cell value, followed again by any string value. It's essentially just performing separate checks, in sequence, which allows you to search for different value types (in this case string wildcard + cell value + string wildcard).

Google Sheets multiple conditional formatting for date range and text

I'm trying to apply multiple conditional formatting to a google sheets column. I want two conditions:
A Column needs to equal/contain "Accepted" from a dropdown cell
B Column needs to contain a future due date that is within 14 days to today
I want to highlight C column based on those two conditions being met with a priority flag for Accepted and has a due date within 14 days of today. Here's what I've got so far:
Custom conditional formatting for column C is:
=(A="Assigned")+(B<=TODAY()+14)
What I'd like to see is:
=(A="Assigned")+(B<=TODAY()+14)+(B>=TODAY())
But it's not working. Either I have to specify the exact reference columns (ex: A5) which aren't what I want, or it's not working at all. Any recommendations?
Yes - just get it right for the first row (say row 2) and the other rows will follow by relative addressing:
=and(A2="Accepted",B2>=today(),B2<=today()+14)
If you want to apply the conditional formatting to more than one column, put in dollar signs to anchor the columns:
and($A2="Accepted",$B2>=today(),$B2<=today()+14)
you were close... this is what would work as well:
=($A2="Assigned")*($B2<=TODAY()+14)*($B2>=TODAY())

Arrayformula - Adding together a dynamically generated list of ranges

I'm looking for a way to add together a dynamically generated list of ranges using (I'm guessing) an ARRAYFORMULA.
The normal way of attacking this is fine if there is a known list of ranges, the example of the results I want would work using this:
=ARRAYFORMULA( A1:A10 + B1:B10 )
In the case I'm after I want to add together ranges in multiple sheets. I don't want the users to have to manually adjust the array formula every time they add a new sheet to be calculated, and I also want to be able to add some logic to include or remove the particular sheet from the calculation, but for now I'm happy to ignore that and just focus on adding cells together.
My approach to this was to create a column with a list of names, each one matching a sheet in the document, and then using that list to dynamically build the list of ranges to add together, using INDIRECT.
.------------.
| sheet1 | <---- SheetListNamedRange
|------------|
| sheet2 |
`------------'
Here's a quick example
=ARRAYFORMULA( INDIRECT("'" & SheetListNamedRange & "'!D4:75") )
There are lots of failure modes depending on how it's done, but this particular formula only puts in the values of the first sheet and ignores any others, which I guess makes sense.
What I'm after is kind of the equivalent of i++ in a loop found in a normal coding language. Is there some way of making this work?
If I understand you correctly, you'd like to get a list generated based on different ranges across different sheets. If your case is as simple as the one you mention in the beginning of your post, the following would do the job.
={Sheet1!A1:A2; Sheet2!B1:B2}
If you want the sum of all these values, you can use SUM.
=SUM({Sheet1!A1:A2; Sheet2!B1:B2})
Please let me know if this isn't what you were looking for, so I can change the answer accordingly.
you can't refer to array of arrays in INDIRECT. you will need to INDIRECT each sheet which contains array.
=SUMPRODUCT(ARRAYFORMULA(INDIRECT(A1&"!"&"D:D")+
INDIRECT(A2&"!"&"D:D")+
INDIRECT(A3&"!"&"D:D")+
INDIRECT(A4&"!"&"D:D")))
note1: in this case result is 25 as sum of 10 + 15.
10 is sum of sheet1!D:D
and 15 is sum of sheet2!D:D
note2: there is no sheet3 and sheet4 which is equal to 0 in INDIRECT
note3: D:D of the sheet where you have the list of sheets needs to be empty

Small in arrayformula (Google Spreadsheet)

I have 5 columns of numbers that I want to sort per row into another set of columns. I figured I need to use small() (e.g. small(a2:e2,1) for f2; small(a2:e2,2) for g2 and so on). Is there away to iterate this for the next rows; if possible using only native google spreadsheet formulas?
Thanks in advance
I was able to make a temporary work around, but I had to use 3 cheat columns. It looks ok for now but I imagine it will be troublesome for really huge numbers.
Here's a sample sheet for reference: https://docs.google.com/spreadsheets/d/1MQTP2XkRsPRAnPQ5wLhkR8JoNVY6YOExVlOkkX8UeRs/edit#gid=0
The original data are in A3:E
The first cheat column (G3:G) simply creates a column of numbers from 1 to the largest number found in the source data. 1-9 is changed to 01-09 for easier searching. "#" is then added at the end-this will come handy later:
Cheat Column 1 =filter(if(row(A:A)=max(A:E)+1,ʺ#ʺ,text(row(A:A),ʺ00ʺ)),row(A:A)<=max(A:E)+1)
The second cheat column (H3:H) combines each row into a string separated by "-" with a "#" marker:
Cheat Column 2=filter(text(A3:A,ʺ00ʺ)&ʺ-ʺ&text(B3:B,ʺ00ʺ)&ʺ-ʺ&text(C3:C,ʺ00ʺ)&ʺ-ʺ&text(D3:D,ʺ00ʺ)&ʺ-ʺ&text(E3:E,ʺ00ʺ)&ʺ#ʺ,A3:A<>ʺʺ)
The last cheat column (I3:I) sorts each line (from cheat column 2) by finding each number from cheat column from 01 up to the max number, then the "#" char (this ensures that each line will still have the # end marker). "Find" will return the "position" of each number or an error if it's not found. By using "if", we can make "find" return the actual number or "" instead.
=filter(arrayformula(if(iferror(find(transpose(filter(G3:G,G3:G<>ʺʺ)),H3:H),ʺʺ), transpose(filter(G3:G,G3:G<>ʺʺ)),ʺʺ)),A3:A<>ʺʺ)
The formula above creates as many columns as there are numbers from cheat column 1. To prevent this, a "-" is added to each number then "Concatenate" is used to combine everything into one massive string with each set separated by "#". The string is then split using the "#" marker.
Cheat Column 3 =transpose(split(concatenate(filter(arrayformula(if(iferror(find(transpose(filter(G3:G,G3:G<>ʺʺ)),H3:H),ʺʺ),ʺ-ʺ&transpose(filter(G3:G,G3:G<>ʺʺ)),ʺʺ)),A3:A<>ʺʺ)),ʺ#ʺ))
Each number is then separated into each corresponding column by using mid().
Small 1 =filter(mid(I3:I,2,2)*1,A3:A<>ʺʺ)
Small 2 =filter(mid(I3:I,5,2)*1,A3:A<>ʺʺ)
Small 3 =filter(mid(I3:I,8,2)*1,A3:A<>ʺʺ)
Small 4 =filter(mid(I3:I,11,2)*1,A3:A<>ʺʺ)
Small 5 =filter(mid(I3:I,14,2)*1,A3:A<>ʺʺ)
Note that the formula above is only for numbers 1-99. For larger numbers, the Text() formulas should have more zeroes to correspond to the number of digits of the biggest number. The Mid() formulas should also be adjusted accordingly.
I would like to stress that I am very far from being a spreadsheet expert and that this solution is very "unoptimized". It requires several cheat columns; with the first one even having more rows than the original data. If anyone can help me get rid of the cheat columns (or at least the first one) I will be very grateful.
How about using SMALL like you mentioned in your question?
=small($A3:$E3,column()-columns($A3:$G3))
You will need to change the ranges accordingly. The last $G$3 is the cell just before the cell where the formula is placed.
Sample

Resources