Forum

Delete equal debits...
 
Notifications
Clear all

Delete equal debits and credits

5 Posts
4 Users
0 Reactions
90 Views
(@hannes04)
Posts: 2
New Member
Topic starter
 

 I am trying to put together some VB code which will compare debits and credits in two columns and when found it should delete both rows.

A debit and a credit always has a blanh cell in the other column. Attached is my attempt. I can get the first debit and credit and delete both rows but what I cannot do is return to the first loop to start in looking in the debits coumn again.

 

Can you please assist

 

Attached is my attempt

 
Posted : 24/01/2019 7:37 am
Philip Treacy
(@philipt)
Posts: 1630
Member Admin
 

Hi Hannes,

There's no workbook attached.

Regards

Phil

 
Posted : 24/01/2019 8:18 pm
(@hannes04)
Posts: 2
New Member
Topic starter
 

Hi Phil,

I obviously did something wrong when attached my workbook

I tried again to drag my w/book to below

It is called dountiloop1.xlsx

Regards

Hannes

 
Posted : 26/01/2019 2:43 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Hannes

When requesting for a macro solution it is best if you can supply the actual file (you can change the values if it contain sensitive info)

We need to see the actual format. Otherwise it is very difficult to develop the macro.

Sunny

 
Posted : 26/01/2019 4:47 am
(@davesexcel)
Posts: 6
Active Member
 

if you want to delete rows, you can't loop through rows from the top and delete. for example, looping through rows and delete row 5, row 6 shifts up, the code will then go to the next row missing the original row 6.

When deleting rows with a loop, you would have to start from the bottom up.

 

you can clear contents though


Sub Button1_Click()
Dim rng1 As Range, rng2 As Range
Dim a As Range, b As Range

Set rng2 = Range("B:B").SpecialCells(xlCellTypeConstants, 23)
Set rng1 = Range("A:A").SpecialCells(xlCellTypeConstants, 23)
For Each a In rng1.Cells
Set b = rng2.Find(what:=a, lookat:=xlWhole)
If b Is Nothing Then
Else
a.ClearContents
b.ClearContents
End If
Next a
End Sub

You can also make the values of a & b ="xxx" then filter out xxx

 
Posted : 29/01/2019 6:17 am
Share: