Forum

Macro to delete row...
 
Notifications
Clear all

Macro to delete rows where positive & Negative values match and match (partial or full in narrative)

3 Posts
2 Users
0 Reactions
189 Views
(@howardc)
Posts: 54
Trusted Member
Topic starter
 

I have values in Col E and Narrative (Descriptions) in Col F

 

Where positive value/s or negative value matches negative value/s or positive value and they sum to zero , then the rows containing these values are to be deleted

 

I have written code to delete values where a positive and negative values matches but need it amended so that where the sum of positive and negative values are zero, then the rows are to be deleted. The alternative is also to look at the narrative and where the narrative matches either full or partial and the values sum to zero, to delete the rows

I have attached sample data showing where I am trying to achieve. The items in yellow are single values where the positive and negative values balance to zero and the items in blue is where several values match to zero

 

Your assistance in this regard is most appreciated

Not sure how to wrap code below

 Sub delete_values_that_Match()
Sheets("Imported data").Select
Dim lRow&, iRow&, c As Range
lRow = Cells(Rows.Count, 5).End(xlUp).Row
For iRow = lRow To 2 Step -1
    If Cells(iRow, 5) > 0 Then
        With Columns(5)
            Set c = .Find(Cells(iRow, 5).Value * -1, LookIn:=xlValues, lookat:=xlWhole)
                If Not c Is Nothing Then
                    Rows(iRow).Delete shift:=xlUp
                    c.EntireRow.Delete shift:=xlUp
                End If
        End With
        
    End If
   
Next iRow
End Sub

 
Posted : 27/05/2020 9:20 pm
(@purfleet)
Posts: 412
Reputable Member
 

Hi Howard
How many rows of data will you have in the workbook on an ongoing basis? I think it will be easier to manually match off if the transaction volume is low or too much effort for excel to work out the potential matches.

The above code works well to match off single items but to get multiples to calculate will take a lot of effort and resources. I had to do something similar for my last company and I concluded that it was just too much work for excel to do.

In the end I had a database where I input an X in the far left column which validated the currency and the sum of the transactions to zero and then moved them to another sheet in the same workbook (with a linking reference). That way could always bring them back to the main reconciliation if the wrong items were matched off and I could also validate the sum of the matched items to zero for each currency on the matched sheet as an extra control.

This reconciliation only had about 150 transactions at anyone point so not hard to look through and match off.

Ultimately, I thought the controls on the spreadsheet in the importing, automated checking to the external system ledger and matching integrity was more important than 5 minutes of manual matching once per day.

Purfleet

 
Posted : 28/05/2020 5:11 pm
(@howardc)
Posts: 54
Trusted Member
Topic starter
 

Thanks for your reply & input

 

The maximum number of rows would be 300

 

The maximum number of values that would equal sum to zero is 10. 90% of the values summing to zero would be 2 (one postive and one negative)

 
Posted : 28/05/2020 9:45 pm
Share: