Conditional fomatting formula to match positive and negative amounts in a single column.

Anonymous
2010-07-24T15:40:02+00:00

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.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2010-07-24T22:44:02+00:00

The following code will, I believe, do what you need:

Sub OffsetFound()

    Dim I As Long

    Dim last As Long

    Dim cell As Range

    last = Selection.Row + Selection.Count - 1

    For Each cell In Selection

        With cell

            If .Font.Strikethrough = False Then

            I = 1

                Do

                    If .Offset(I, 0) = -cell And .Offset(I, 0).Font.Strikethrough = False Then

                        .Font.Strikethrough = True

                        .Offset(I, 0).Font.Strikethrough = True

                        Exit Do

                    End If

                    I = I + 1

                Loop Until .Offset(I, 0).Row > last

            End If

        End With

    Next cell

End Sub


If this answer solves your problem, please check, Mark as Answered. If this answer helps, please click the Vote as Helpful button. Cheers Shane Devenshire

Was this answer helpful?

10+ people found this answer helpful.
0 comments No comments
Answer accepted by question author
Anonymous
2010-07-25T16:00:26+00:00

Unless I am implementing Teethless mama's conditional formatting formula incorrectly, it (and all the posted variations derived from it) appears to only "strike through" the first of the positive/negative paired values... the solution by Mike H does the "strike through" to both the positive and negative values.

I have no problem to get the formatting as expected, i.e. striking out positive and negative values "pairwise" leaving any unmatched unformatted.

Here is an example of data and formatting (red background used instead of strikethrough for readability reasons) using the formatting formula:

=SMALL(IF($A$2:$A$21=-A2,1),COUNTIF($A$2:A2,A2))

Regards / Lars-Åke

Was this answer helpful?

0 comments No comments
Answer accepted by question author
Anonymous
2010-07-24T23:00:24+00:00

The following code will, I believe, do what you need:

Sub OffsetFound()

    Dim I As Long

    Dim last As Long

    Dim cell As Range

    last = Selection.Row + Selection.Count - 1

    For Each cell In Selection

        With cell

            If .Font.Strikethrough = False Then

            I = 1

                Do

                    If .Offset(I, 0) = -cell And .Offset(I, 0).Font.Strikethrough = False Then

                        .Font.Strikethrough = True

                        .Offset(I, 0).Font.Strikethrough = True

                        Exit Do

                    End If

                    I = I + 1

                Loop Until .Offset(I, 0).Row > last

            End If

        End With

    Next cell

End Sub

 


If this answer solves your problem, please check, Mark as Answered. If this answer helps, please click the Vote as Helpfulbutton. Cheers Shane Devenshire

I suggest that you put in a clearing of strike throughs at the beginning if you want to run the macro again after changing some data in the selected range.

For each cell in Selection

   cell.Font.Strikethrough = False

Next cell

Regards / Lars-Åke

Was this answer helpful?

0 comments No comments
Answer accepted by question author
Anonymous
2010-07-24T21:16:04+00:00

Rob,

Select the range and apply this conditional format using font strikethrough and I think this does what you want in a single column

=COUNTIF($A$1:$A$11,A1)+COUNTIF($A$1:$A$11,-1*A1)=2


If this post answers your question, please mark it as the Answer.

Mike H

Was this answer helpful?

0 comments No comments

49 additional answers

Sort by: Newest
  1. Anonymous
    2010-07-25T18:04:30+00:00

    Yes, I see that now... see my response to Lars-Åke for additional thoughts.

    Was this answer helpful?

    0 comments No comments