Delete row under condition

Jeeremy7

Board Regular
Joined
May 13, 2020
Messages
110
Office Version
  1. 365
Platform
  1. Windows
Hey Guys,

I'm going to start explaining this simple as possible, let me know if I don't make sense !

In my workbook there's sheet "A" and "B"
If the value on the same row for column F and G is the same on sheet "A" and "B" then delete that row in sheet "A"

Thanks !
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I think this will do as you have described

VBA Code:
Sub DeleteOnSameRow()
Dim lst As Long
Dim i As Long
Dim testA As String
Dim testB As String

xlSettings False

lst = Sheets("B").Range("F1").CurrentRegion.Rows.Count

For i = lst To 2 Step -1
    testA = Sheets("A").Range("F" & i).Value & Sheets("A").Range("G" & i).Value
    testB = Sheets("B").Range("F" & i).Value & Sheets("B").Range("G" & i).Value
    
    If testA = testB Then
        Sheets("A").Rows(i).Delete xlUp
    End If
Next i

xlSettings True

End Sub

Sub xlSettings(t As Boolean)
With Application
    .ScreenUpdating = t
    .EnableEvents = t
    .Calculation = IIf(t, xlCalculationAutomatic, xlCalculationManual)
End With
End Sub
 
Upvote 0
Thanks a lot :) I will try this as soon as I can and let you know !
 
Upvote 0
I think this will do as you have described

VBA Code:
Sub DeleteOnSameRow()
Dim lst As Long
Dim i As Long
Dim testA As String
Dim testB As String

xlSettings False

lst = Sheets("B").Range("F1").CurrentRegion.Rows.Count

For i = lst To 2 Step -1
    testA = Sheets("A").Range("F" & i).Value & Sheets("A").Range("G" & i).Value
    testB = Sheets("B").Range("F" & i).Value & Sheets("B").Range("G" & i).Value
   
    If testA = testB Then
        Sheets("A").Rows(i).Delete xlUp
    End If
Next i

xlSettings True

End Sub

Sub xlSettings(t As Boolean)
With Application
    .ScreenUpdating = t
    .EnableEvents = t
    .Calculation = IIf(t, xlCalculationAutomatic, xlCalculationManual)
End With
End Sub
Hmm not sure why but nothing happened when I tried to run the Macro :/
 
Upvote 0
Hi,​
without any attachment it's just a guessing challenge for some mind readers forum …​
 
Upvote 0
Here's an example, sheet 1 and 2 and the letters would be the columns.
In yellow is what would need to deleted (In that example when column "D" and "E" of the 2 different sheets would match

Thanks :)

Book3
DEFGHIJKLMNOP
5SHEET 1SHEET 2
6ABCDEFABCDEF
7xxxxxxxxxaaacccxxxxxxxxxxxxaaacccxxx
8xxxxxxxxxaaahhhxxxxxxxxxxxxllldddxxx
9xxxxxxxxxllldddxxxxxxxxxxxxbbbdddxxx
10xxxxxxxxxbbbdddxxxxxxxxxxxxdddfffxxx
11xxxxxxxxxiiidddxxxxxxxxxxxxaaadddxxx
12xxxxxxxxxdddfffxxx
13xxxxxxxxxpppdddxxx
14xxxxxxxxxaaadddxxx
Sheet1
 
Upvote 0
How many rows in real workbook in each worksheet ?​
 
Upvote 0
According to your attachment a VBA demonstration for starters :​
VBA Code:
Sub Demo1()
        Dim R&, S$(), V()
    With Sheet2.[A1].CurrentRegion.Rows
            ReDim S(1 To .Count)
        For R = 1 To .Count
            S(R) = Join(Application.Index(.Item(R).Value2, 1, 0))
        Next
    End With
    With Sheet1.[A1].CurrentRegion.Rows
            ReDim V(1 To .Count, 0)
        For R = 1 To .Count
            V(R, 0) = Join(Application.Index(.Item(R).Value2, 1, 0))
        Next
           V = Application.Match(V, S, 0)
           R = Application.Count(V)
        If R Then
            Application.ScreenUpdating = False
           .Columns(.Columns.Count + 1).Value2 = Application.IsNumber(V)
           .Resize(, .Columns.Count + 1).Sort .Cells(1, .Columns.Count + 1), 1, Header:=2
            Union(.Item(.Count - R + 1 & ":" & .Count), .Columns(.Columns.Count + 1)).Clear
            Application.ScreenUpdating = True
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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