Excel: Format cells if it finds similar strings in cells - excel

Given the example:
A1: Smith, John Michael
A2: John Michael Smith
What is the formula if I want to format cells (let's say color the cells green) when it finds the string "Smith" in both A1 and A2?
A1 -> list from excel file
A2 -> list from database
I'm comparing a list of names extracted from a user database and the list of names on an Excel file to see if which ones are missing in the database.

Assume you place the word you are looking for in A4, you could use the following formula:
=AND(ISNUMBER(SEARCH(A4,A1)),ISNUMBER(SEARCH(A4,A2)),NOT(TRIM(CLEAN(A4))=""))
Search will look for the text entered in cell A4 and see if it can be found in A1. If it is found it will return a number and if is not found it will return an error.
Isnumber checks to see if the search returned a number. if search found the word entered in A4 in A1, it will return the number of the starting position and is number will then return a value of TRUE.
The process is then repeated for the text in A2.
In order to say that the text is found in both locations you need all arguments in the AND formula to be TRUE. if any one of them is false AND will return a value of FALSE.
The final step will be to apply conditional formatting to the cells. Use formula as your method for your conditional formula control and use the above formula in the space provided. Set your special format for when your formula returns a true value.
Depending on how you apply your conditional formatting, you may want to use $A$4 instead of A4. Same goes for A1 and A2.
The last logical check that was added was to make sure that if no information was entered in A4, or a space was entered in A4 that the check would colour the cells. In other words it will only colour the cells if there is actually something to look for in A4.

Related

Google Sheets or Excel: setting the value of a remote cell from a formula

Is there a way to create a formula in one cell that will change the value in another cell based on some criteria, without scripting? Example: cell a1 contains a numerical value. cell b1 contains a value from a drop-down list, say, "YES,NO". If cell b1 is set to "YES" I want to remove (set to zero) the value in cell a1. What I'd like to do is have a formula in cell c1 that interrogates b1 and sets the value in a1 accordingly. Is the only way achieve this writing code and using setValue?
you cant remove it without a script. you can visually hide it in various ways. if the A1 is subject of further sum (as in your case per your comment) the sum formula can be always altered to reflect desired output. example:
if your formula is
=SUM(A1, C5, D22)
you can do
=SUM(IF(B1="YES", 0, A1), C5, D22)
Use the following on the cell you need the calculation (or zero) on:
=IF (B1="YES",0,SUM(A:A))
Using the given formula, you would do the SUM calculation for the whole Column A if the value on B1 is "YES", if not, then a 0 would be placed on the cell you put the formula on.

How to calculate conditional cell formula, with adjacent cell formula dependent on 1st cell's calculated, not printed value?

I am trying to figure an Excel formula and Google is not helping.
I almost have what I am trying to do, but need a 'dummy' column where I do the math in the column cells.
What this means:
1) What I have working:
Cell A1, with math formula (I wish to delete this 'dummy' cell and incorporate this into the formula in Cell B1, see further explanation below)
=SUM((6.75*1)+(5.73*2)+3)
Cell B1, with value from Cell A1 but limited to an integer less than or equal to 80
=IF(SUM(A1)>80, 80, SUM(A1))
Cell C1, with a value looking at Cell B1 and entering in this cell either 0 or any integer greater than 80
=IF(SUM(A1)>80,SUM(A1)-80,"0")
Note: This works perfectly, I change any values in the Cell A1 formula and it correctly reflects in Cells B1 & C1.
2) The missing piece:
I would like to combine the two formulas above in cells A1 & B1 into one cell, and still have the same results described above for each of the cells.
To articulate this another way is:
have a cell with a math formula,
calculate the results of that formula, and then,
enter back in the same cell that formulas results,
with the condition of 'less than or equal to 80'
while a formula in an adjacent cell is dependent on the calculated, but un-printed, value of the first cell.
As an example:
Using only Cells A1 and B1 in a spreadsheet, and combining the above working formulas (which do not work for me in Excel), it would look like this:
Cell A1:
=IF(SUM((6.75*10)+(5.73*7)+8.5)>80, 80, SUM(B21))
Note: Cell A1 formula from above, =SUM((6.75*1)+(5.73*2)+3), combined with Cell B1 formula from above, =IF(SUM(A1)>80, 80, SUM(A1)) (with the Cell A1 formula replacing both 'A1' values in the Cell B1 formula).
Cell B1:
=IF(SUM(A1)>80,SUM(A1)-80,"0")
Note: Identical to the Cell C1 formula above.
Is it possible to do this, calculate the results of a cell's formula, while a formula in an adjacent cell is dependent on the calculated, but un-printed, value of that first cell?
I realize writing this out, it's more complicated than I originally anticipated, which explains why Google wasn't getting me anywhere.
Thanks for any hints.
Phil
Strictly speaking, this is not possible. A cell has only 1 value and that is the result of all calculations. The IF statement is not hiding the value of the cell. It is changing the value.
A formula to another cell can only use the final value of the cell. It can't extract part of the formula in the other cell. There's no way for Excel to know which part to extract, even if there's only a single calculation in an IF statement.
That said, there is a different workaround possible in your case... and that is to change how your value is displayed through custom formatting. Formulas change the value of cells, whereas formatting changes how those values are displayed.
Place your formula in cell A1: =6.75*10+5.73*7+3
Right click on cell A1 and select Format Cells...
Make sure you're on the Number Tab
In the Category column, select Custom
Enter this formula in the Type box: [>80]"80";[<=80]General
Enter this formula in B1:=IF(A1>80,A1-80,0)
Check that the number format of B1 is still "General" or "Number"
The result is A1 has calculated and stored the actual value, but displays the text string "80" if it's value is above 80. You can then use the actual value from A1 in other formulas.
NOTE: This type of custom formatting is extremely poor practice as it can become very confusing and very error prone. The value of the cell is different to what it is showing and if other users are unaware, creating new formulas referring to the affected cell can unwittingly produce incorrect and/or unexpected results.
In particular, Excel tries to be helpful and can automatically copy the formatting from one cell to another if it is next to the original cell or if it refers to only the original cell in a basic formula. Copying and pasting also copies the formatting by default. Unintentionally copying the formatting to other cells will also alter how they appear.
Also note that you don't need to put SUM() around a formula that already had the addition operators included; and Excel uses order of operations so you don't need the brackets to do multiplication before addition.
Lastly, you could also just use =MAX(A1-80,0) in B1.

Highlighting entire row if cell contains specific text

I require to highlight an entire row in Excel if a cell string contains the word "site" in column G. I am using conditional formatting with a formula which uses the following formula which doesn't work.
=INDIRECT("g"&ROW())=MID("g"&ROW(),FIND("site","g"&ROW(),1),4)
On a side note: the following works perfectly but only for exact matches where the content of the cell ONLY contains "site" as string:
=INDIRECT("g"&ROW())="site"
You don't need to use INDIRECT of MID, if you can use some lock mechanisms:
=FIND("site",$G1)>0
Here, you will see the active cell is A1, so the corresponding row Excel will compare it to will be G1, when conditional formatting looks at cell A2, it will compare it to G2.
When the conditional formatting looks at cell B2, it will compare it to G2 again because G was locked (via the $ symbol).
That said, your formula was not working because FIND("site","g"&ROW(),1) fails. The second argument gives the text g# (where # represents the row number) and the search fails).

In excel how to create function to find a word in one column and place another word in different column

I'm very new to excel, and I'm trying to figure this out...
If any cells in column A are empty or have the word 'EMPTY' I want it to generate the word 'EMPTY' into a cell in a different column. For example: If A1 and A2 have the word 'EMPTY' in the cell, then I want the matching cell in column D to have that word as well (D1 and D2).
I have been messing around with =if(A2,EMPTY)(D2,EMPTY), but I'm clearly missing something.
I'm sorry if this has been asked, or is so simple, it's hard to phrase the exact wording to find a question that will give me an answer.
Using your example, in cell D1 use this formula and then copy it down:
=IF(OR(COUNTIF(A1,"*empty*")>0,A1=""),"EMPTY","NOT EMPTY")
You can replace the "NOT EMPTY" with the result of your choice for if the cell isn't empty, or you can just use "" to return a blank result.
Try this:
=IF(OR(A1="empty",""),"empty",0)
Assuming you've put "empty" in cell A1, or if the cell A1 is empty as well. You can then increment that formula from, say, B1 down to B10 (then B2 will be checked against A2, B3 against A3, etc).
As a general rule, in Excel, if in the formular bar you start typing
=IF(
Then there will be a small drop-down text that will give you a clue as to what to write next...

How to format a cell to turn a color based on the text value of a cell that corresponds to a list of text values

In cells A1:A500 I have names like "Fred Flintstone" for example. In cells B1:B500, I have a drop down box that indicates "PASS" or "FAIL". In cells AA1:AA500 I have created a formula that will pull only the names from A1:A500 that have "FAIL" in their respective B1:B500 column.
What conditional formula could I use so that in cells C1:C500, they will turn yellow if there is a name on the list of names that is contained in AA1:AA500?
So if A1 equals "Fred Flintstone" and he is a "FAIL" in B1, his name gets put into AA1. I then need Cell C1 to turn yellow based on the fact that his name appeared on the AA list.
You can use MATCH to see if the name appears in column AA. I suggest something like this:
Select the cells to be highlighted (make sure that you start with cell C1 to make it the active cell).
Insert the MATCH formula, wrapped in ISNUMBER to get a boolean value. MATCH returns a number (the row number of a match) or an error (if there are no matches):
=isnumber(match(A1,AA$1:AA$500,0))
And make sure you have the appropriate format picked.
Click OK and you should be done:
Click on cell C1 and apply conditional formatting with the "formula is" option:
=COUNTIF(AA:AA,A1)=1
and pick yellow as the background color.
Then copy C1 and PasteSpecialFormats to the rest of column C

Resources