Hello,
I have a single column of both positive and negative amounts. I am looking for a formula to insert in the conditional formatting option that will show a "strikethrough" effect for those that match. I have inserted another column and added the absolute
function to those amounts, sorted them, and used the "countif" formula, strikethrough effect in the conditional formatting to accomplish this. However, I was wondering if I could accomplish this without adding this second column.
Thanks for looking at my request.
Rob, you have already got a macro for this, but I could not give up on the challenge to do this by a conditional formatting formula as you originally asked for.
In case you or someone else need a solution for this where you can't allow macros and without having any helper columns , here is my suggestion.
Assuming the table of amounts is in cells A2:A21 use the following formula for conditional formatting:
(cells A1, A22, and A23 should not contain any numbers. Cells A22 and A23 should not be empty if you want to be able to handle amounts equal to 0)
=IFERROR(MATCH(ROWS($1:2),B$1:B1,0),IFERROR(SMALL(IF(A3:A$23=-A2,ROW(A3:A$23)), SUM((B$1:B1>ROWS($1:2))*(A$1:A1=A2))+1),0))
(See Note below if you don't have Excel 2007 or later)
Select cells A2:A21 and then Home tab->Styles section->Conditional Formatting->New Rule...->Use a formula to determine which cells to format
Enter the above formula in the text field Format values where this formula is true, Click on Format... and choose your format. Click OK until all dialogues are closed.
If you want to "see" how it works, you can put the formula it in cell B2 and copy it down to cell B21. But there is no other need for this column soyou can remove it later .
Note: the formula is an array formula so it has to be confirmed with CTRL+SHIFT+ENTER rather than just ENTER.
The first match checks if the "current" row number is already put somewhere "above" in this column. In that case just put that row's number on the current row.
Otherwise look for numbers on rows "below" the current row that are the negative of the amount in the current row. Skip matches on rows that are already "noted" for on rows "above" the current row as they are already "reserved". Note/reserve the first match
that is not already "reserved" by noting the matching row's number on the current row. If no match can be found note 0 for this row indicating that there is no match for this entry.
When this formula has been "executed" for the entire range it will contain a 0 on the rows that are not matched. And on the rows that are matched the row number of the respective matching row will be found. The conditional formatting will format everything
that is not 0, i.e that is matched.
Here is an example on how it can look like where I use red cell color rather than strikethrough as formatting:
Hope this helps / Lars-Åke
Note: If you don't have Excel 2007 or later you can't use IFERROR(), but then you can translate it is like this using IF() and ISERROR():
IFERROR(stuff1, IFERROR(stuff2,0)) -> IF(ISERROR(stuff1),IF(ISERROR(stuff2),0,stuff2),stuff1)
This formula becomes rather long:
=IF(ISERROR(MATCH(ROWS($1:2),B$1:B1,0)),IF(ISERROR(SMALL(IF(A3:A$23=-A2,ROW(3:$23)), SUM((B$1:B1>ROWS($1:2))*(A$1:A1=A2))+1)),0,SMALL(IF(A3:A$23=-A2,ROW(3:$23)), SUM((B$1:B1>ROWS($1:2))*(A$1:A1=A2))+1)),MATCH(ROWS($1:2),B$1:B1,0))