Conditional cell for incorrect value excluding blanks - excel

Trying to define a conditional cell that highlights the value in A1 when that value is not equal to the sum of values in B1 and C1, but excluding when B1 and/or C1 is blank
In the mockup below, only A3 should be highlighted.
I have tried with numerous formulas, none of which works correctly:
=SUMIF(B1:C1,"<>",B1:C1)
=IF(OR(ISBLANK(B1),ISBLANK(C1)),"",B1:C1)
=SUM(IF(COUNTBLANK(B1:C1),"",SUM(B1:C1))B1:C1)
Many thanks for indicating my error!

You want to highlight A only when B and C are not blank and A is not equal to B+C so something like AND(B1<>"",C1<>"",A1<>B1+C1) should work for you

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.

Excel 2010: Set cell value to same value as other cell, even if cell is empty

In Excel 2010, I want cell A1 to have the same value as cell A2. So I set a formula in A1:
=B1
that works fine if B1 has a value. But, if B1 is empty, then A1 shows "0". I want A1 to be empty if B1 is empty.
As a workaround, I'm using the following formula in A1:
=IF(B1="", "", B1)
Is there an easier and more elegant way to set a cell to the same value as other cell? (without VBA)
That's the way Excel works I'm afraid. =B1 will display a zero if B1 is empty. Futhermore ISNNUMBER(B1) will return True. So it is a genuine zero, not something formatted as a zero.
A common workaround is to use something like:
=IF(ISBLANK(B1), "", B1)
which, I think, is more elegant than an empty string comparison.
Google spreadsheet works exactly as you need. Using
=A1
in B1, you get the desired empty B1 when A1 is empty.
Under Excel Options > Advanced > Display options for this worksheet, is a tick box called 'Show a Zero in Cells that have zero value'. If you un-tick it then your formula will display blank if they result in zero. Only downside is that all cells that have a zero value (not from a formula) will also display blank.

IF/AND/OR statements

I have applied the conditional formatting in B1 with the formula =IF(AND(A1<>"APPLE",B1<>""),TRUE,FALSE). By this formula, I am telling Excel to highlight the cell B1 in red when B1 has any number but A1 does not have "Apple". Just to simply it what exactly I want is if A1 does not have "Apple" and B1 has any number, highlight B1 in red. The above formula is working fine for me.
But here is my problem. Now what i want is if A1 does not have either "Apple" or "Mango" and B1 has any number, highlight B1 in red. I tried with the formula =IF(AND(OR(A1<>"APPLE",A1<>"MANGO"),B1<>""),TRUE,FALSE) This formula is not giving me desired result.
Could you please advice me what changes i need to make to be able to get the desired result.
Try
AND(A1<>"APPLE",A1<>"MANGO",B1<>"")
You can drop the IF because AND already returns TRUE/FALSE

Excel: IF (cell C2 is not anywhere in column A OR not anywhere in column B) then return cell C2 in Cell D2

I have checked alot of INDEX and MATCH formula but can't nail this if someone can point me in the right direction to compare one cell in the C column against all cells in Column A and Column B and if it is in neither enter C2 in D2 so I have a list of numbers not in either column A or B.
So the idea is I check every C column cell against the other two columns and show the C cells that are in netiher.
Hopefully this pseudo code helps explain:
IF (cell C2 is not anywhere in column A OR not anywhere in column B) then return cell C2 in Cell D2
This one works for one column check:
=INDEX(C$2:C$23,MATCH(C2,A$2:A$23,0))
but I need two column check but the below does not work for me as it just says #N/A even for the row that was working for the single column check formula above. I I wondering if I can put an OR in the middle of the two matches or maybe you can suggest it a different way.
=INDEX(C$2:C$23,MATCH(C2,A$2:A$23,0),MATCH(C2,B$2:B23,0))
Thanks in advance.
Try using COUNTIF like this
=IF(COUNTIF(A$2:B$23,C2)=0,C2,"")
or if columns are not adjacent
=IF(COUNTIF(A$2:A$23,C2)+COUNTIF(B$2:B$23,C2)=0,C2,"")
Those will return C2 value if it's not in either column....otherwise a blank
....if you really want to use MATCH try this version....
=IF(COUNT(MATCH(C2,A$2:A$23,0),MATCH(C2,B$2:B$23,0))=0,C2,"")
And one more version using VLOOKUP:
=IF(AND(ISERROR(VLOOKUP($C$2,$A:$A,1,0)),ISERROR(VLOOKUP($C$2,$B:$B,1,0))),"",$C$2)

Retrieving Values From Excel Merged Columns

I'm doing a hlookup against a value that spans multiple columns. My data is similar to this:
A B C D
---------------------------
1| Col1 Col2
2| x y z w
3|
4|
In rows 3 and 4 (A3, B3, C3, D3, etc.), I'd like to put formulas that will do an hlookup somewhere else in the workbook. The trick is, I'd like it to look up "Col1" for columns A and B and "Col2" for columns C and D. "Col1" is in A1, but is really A1 and B1 merged. When I reference A1, "Col1" appears, but when I reference B1, the return value is blank.
Any ideas?
Here is another solution that can also work when the merged cells are of different widths, let me illustrate with an example:
Open a fresh Excel, merge B1, C1, D1
Type Col1 in the merged cell
In B2, type formula =B1, and in C2 =C1, in D2 =D1
You should see B2 to be Col1 while C2, D2 are 0
In B3, type the formula =A3, copy it
Right-click the merged cell B1:D1, select "paste special -> formulas"
You should see the merged cell being 0
Type Col1 in the merged cell
You should now see all B2, C2, D2 to be Col1, i.e. now you can reference the merged cell as you expect it to be.
If you can multiple merged cells, each of different widths, just paste the formula to all of them in one go.
The reason behind this works is because of a perculier design choice by Microsoft. It seems that when you paste formulas in merged cells, each underlying cell receives the formula (in contrast, if you enter a value, only the top-left cell gets it) So you can use it at your advantage and paste a formula that reference the cell next to it, and then overwrite the top-left cell with the value you want, then every cell underlying the merged cell will have that value.
To get access to the "Col1" and "Col2" labels, you can use the following:
=INDEX($1:$1,1,COLUMN()-MOD(COLUMN()-1,2))
Note: This assumes that you are grouping together the same number of cells. If it were three cells, you would just change the last number in the formula to a 3, and so on.
Edit: Here's how it works:
INDEX($1:$1,1, x ) returns the value of the cell in row 1, column x. If your table is not actually located in the top left corner of the worksheet, you can change this to the actual range that includes all of your merged labels. In this case, it would be:
INDEX($A$1:$D$1,1, x )
COLUMN() returns the column number of the current cell (1 in column A, 2 in column B, etc.)
MOD(COLUMN()-1,x) returns an offset from the current column to the column that holds the proper label
I've built a simple function in vba that will solve this problem:
Function mergedText(rngMergedCell As Range)
If rngMergedCell.MergeCells = True Then
mergedText = rngMergedCell.MergeArea(1, 1)
Else
mergedText = rngMergedCell
End If
End Function
If the cell is a merged cell, the function will return the value in the first element of the merged cell - this is where the merged cell stores its value
A more generic variant of e.James's proposal is :
={INDEX($A$1:A1, 1, MAX(NOT(ISBLANK($A$1:A1))*COLUMN($A$1:A1)-COLUMN($A$1)+1))}
This relies on the fact that the merged cells are empty except for the first one (unless you are in a case like Martin's proposal).
Note: The curly braces are there to mark an array formula (do not enter them, just press alt+return to validate the formula in the cell).
I realize I am late to this thread but I found a really simple answer to this.
If, for example, your label is merged across 4 columns a1:d1, and if you reference b1, you will return "". For dynamically finding the right labels use this fx in your new table:
=if(OriginalTable!B1="",ThisTable!A1,OriginalTable!B1)
I am sure you will realize that this will capture ranges in e1:h1 etc as you drag across.
That's it. Hope it helps someone.
Cells B1 and D2 contain no values, only A1 and C1 have something inside them.
So you'll just have to make sure that your formulas in columns A and B both refer to A1 as the lookup value, and that your formulas in columns C and D both refer to C1 for the lookup value.
With the new dynamic reference, there are more options now. Here is a generic function I wrote that will search to the left of the cell and return the first value. It is NOT optimized, but it does the job for me.
=LET(
TargetCell, A1,
TargetRow, ROW(TargetCell),
TargetCol, COLUMN(TargetCell),
RowReference, INDIRECT(TargetRow & ":" & TargetRow),
RowValues, TRANSPOSE(FILTER(RowReference,ISBLANK(RowReference)=FALSE)),
RowValueColumns, MATCH(RowValues, RowReference,0),
ReturnColumn, MAX(FILTER(RowValueColumns,RowValueColumns<=TargetCol)),
Return, INDIRECT(ADDRESS(TargetRow,ReturnColumn)),
Return
)

Resources