If column E equal to column F then delete all that rows
-
- Banned
- Posts: 233
- Joined: 28 Jul 2018, 17:29
If column E equal to column F then delete all that rows
If column E equal to column F then delete all that entire rows in sheet2
You do not have the required permissions to view the files attached to this post.
-
- 2StarLounger
- Posts: 128
- Joined: 08 Mar 2010, 13:53
- Location: Missouri
Re: If column E equal to column F then delete all that rows
Adapt this to your needs
Code: Select all
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Application.ScreenUpdating = False
Dim i as long
For i = 1 To 90
If Range("E" & i).Value = Range("F" & i).Value Then Rows(i).EntireRow.Delete
Next i
Application.ScreenUpdating = True
end sub
Last edited by Oliver on 22 Aug 2018, 08:18, edited 1 time in total.
Regards,
Oliver
“Just because something doesn't do what you planned it to do doesn't mean it's useless.” -Thomas Edison
Oliver
“Just because something doesn't do what you planned it to do doesn't mean it's useless.” -Thomas Edison
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: If column E equal to column F then delete all that rows
Modifying Rudi's solution from your recent other thread:
Code: Select all
Sub Delete_Matches()
Application.ScreenUpdating = False
Range("A1").EntireColumn.Insert
Range("A1").CurrentRegion.Columns(1).FormulaR1C1 = "=RC[5]=RC[6]"
Range("A1").CurrentRegion.AutoFilter Field:=1, Criteria1:="TRUE"
With ActiveSheet.AutoFilter.Range
On Error Resume Next
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
End With
ActiveSheet.AutoFilterMode = False
Range("A1").EntireColumn.Delete
Application.ScreenUpdating = True
End Sub
Best wishes,
Hans
Hans
-
- Banned
- Posts: 233
- Joined: 28 Jul 2018, 17:29
Re: If column E equal to column F then delete all that rows
Thnx HansV and Oliver for giving ur precious time and great support to this post
Problem Solved
Problem Solved
-
- Lounger
- Posts: 27
- Joined: 04 Jun 2013, 08:32
- Location: North Yorkshire, UK
Re: If column E equal to column F then delete all that rows
I know the OP has always been answered, but in your code, I'd always recommend processing rows in reverse order if deleting rows.Oliver wrote:Adapt this to your needs
Code: Select all
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Application.ScreenUpdating = False Dim i as long For i = 1 To 90 If Range("E" & i).Value = Range("F" & i).Value Then Rows(i).EntireRow.Delete Next i Application.ScreenUpdating = True end sub
Imagine you are on row 10 and the check is true. You delete that row and all rows move up; row 11 then becomes row 10. In your code, the counter increments and you move on to the new row 11, ignoring the old row 11 (which is now row 10).
Changing "For i = 1 To 90" to "For i = 90 to 1 Step -1" avoids this issue.
-
- Banned
- Posts: 233
- Joined: 28 Jul 2018, 17:29
Re: If column E equal to column F then delete all that rows
Thnx Mirfield for the info
-
- Banned
- Posts: 233
- Joined: 28 Jul 2018, 17:29
Re: If column E equal to column F then delete all that rows
Code: Select all
Sub STEP3()
Application.ScreenUpdating = False
Range("A1").EntireColumn.Insert
Range("A1").CurrentRegion.Columns(1).FormulaR1C1 = "=RC[5]=RC[6]"
Range("A1").CurrentRegion.AutoFilter Field:=1, Criteria1:="TRUE"
With ActiveSheet.AutoFilter.Range
On Error Resume Next
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
End With
ActiveSheet.AutoFilterMode = False
Range("A1").EntireColumn.Delete
Application.ScreenUpdating = True
End Sub
-
- 2StarLounger
- Posts: 128
- Joined: 08 Mar 2010, 13:53
- Location: Missouri
Re: If column E equal to column F then delete all that rows
Try this:
AfterAdd
After
Code: Select all
Application.ScreenUpdating = False
Code: Select all
ThisWorkbook.Worksheets("Sheet1").Select
Regards,
Oliver
“Just because something doesn't do what you planned it to do doesn't mean it's useless.” -Thomas Edison
Oliver
“Just because something doesn't do what you planned it to do doesn't mean it's useless.” -Thomas Edison
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: If column E equal to column F then delete all that rows
Alternatively:
Code: Select all
Sub STEP3()
Application.ScreenUpdating = False
With Worksheets("Sheet1")
.Range("A1").EntireColumn.Insert
.Range("A1").CurrentRegion.Columns(1).FormulaR1C1 = "=RC[5]=RC[6]"
.Range("A1").CurrentRegion.AutoFilter Field:=1, Criteria1:="TRUE"
With .AutoFilter.Range
On Error Resume Next
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
End With
.AutoFilterMode = False
.Range("A1").EntireColumn.Delete
End With
Application.ScreenUpdating = True
End Sub
Best wishes,
Hans
Hans
-
- Banned
- Posts: 233
- Joined: 28 Jul 2018, 17:29
Re: If column E equal to column F then delete all that rows
Thnx HansV and Oliver Sir for ur great support