Highlight Rows Based on the Sum of Multiple Cells

Captain_Conman

Board Regular
Joined
Jun 14, 2018
Messages
54
Hello!

I currently have the following macro that highlights "offsets" in my spreadsheet.

Code:
Sub Offsets()


Dim Cell As Variant


For Each Cell In Range("B2:B2500")


Dim rng As Range
Set rng = Range(Cell, Cell.Offset(1, 0))


If Application.WorksheetFunction.CountIf(Range("B2:B2500"), Cell) > 1 Then
    If Cell.Offset(0, 1).Value = Cell.Offset(1, 1).Value * -1 Then
    rng.EntireRow.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    End If
    End If
Next


End Sub

For example, the following red transactions would be an offset.

Store #Purchase OrderAmountClass
Store 1513
A015130005080

<tbody>
</tbody>
12.43Debit Memo
Store 1513
A014460005574

<tbody>
</tbody>
7.14Debit Memo
Store 1513A014460005574(7.14)Credit Memo
Store 1583
A015950005582

<tbody>
</tbody>
(78.67)Credit Memo
Store 1583
A015970001912

<tbody>
</tbody>
19.44Debit Memo

<tbody>
</tbody>



However, there are sometimes three or four lines that can offset each other as seen in red below.

Store #Purchase OrderAmountClass
Store 1513
A015130005080

<tbody>
</tbody>
12.43Debit Memo
Store 1513
A014460005574

<tbody>
</tbody>
7.14Debit Memo
Store 1541
A015130004085

<tbody>
</tbody>
(25.42)Credit Memo
Store 1541
A015130004085

<tbody>
</tbody>
(25.42)Credit Memo
Store 1541
A015130004085

<tbody>
</tbody>
42.37Debit Memo
Store 1541
A015130004085

<tbody>
</tbody>
50.82Debit Memo
Store 1541
A014340077651

<tbody>
</tbody>
96.75Debit Memo
Store 1583
A015950005582

<tbody>
</tbody>
(78.67)Credit Memo
Store 1583
A015970001912

<tbody>
</tbody>
19.44Debit Memo

<tbody>
</tbody>

I am trying to write a macro that will look through matching POs and highlight multiple rows that sum to zero, as seen in the example above. I can't quite seem to figure this one out.

I hope this is clear, any advice is greatly appreciated.
 
Last edited:
The functionality of the second code you posted (Post #7 ) is exactly what I need. However, being that it cannot address more than 15 unique identifiers, is there a way to exempt anything greater than 15 from the code? For example, if the unique identifier in column A > 15 cut and paste these lines into sheet two, and continue running the macro on sheet 1?
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Mick,

I actually think I just found a way to reduce the amount of data that will be pulled during the export. This should reduce the amount of unique identifiers in column A and allow the macro to work properly! Again, I cannot thank you enough for all the help you have provided. I could not have done this without you and really appreciate your work. THANK YOU THANK YOU THANK YOU!!!!!
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,554
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top