delete matches by vba (macro correction)

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

delete matches by vba (macro correction)

Post by zyxw1234 »

Code: Select all

Sub Delete_Matches()
    Dim wb As Workbook
    Set wb = Workbooks.Open("C:UsersWolfieeeStyleDesktop1.xls")
    Set ws = wb.Worksheets.Item(1)
    With ws
    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 With
    wb.Save
    wb.Close
End Sub
Hi Experts,
looking for a macro correction
Plz remove the on error resume next line in this macro

https://eileenslounge.com/viewtopic.php ... 7&p=236961

User avatar
HansV
Administrator
Posts: 78465
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: delete matches by vba (macro correction)

Post by HansV »

The line On Error Resume Next is there to ensure that you won't get an error message if there are no rows that satisfy the AutoFilter condition. Why do you want to remove it?
Best wishes,
Hans

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: delete matches by vba (macro correction)

Post by zyxw1234 »

On error resume next line (Professional coder's try to ignore these line in the macro & me too.. sir, it creates issues sometimes that's y)

User avatar
Leif
Administrator
Posts: 7209
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: delete matches by vba (macro correction)

Post by Leif »

zyxw1234 wrote:
26 Jul 2020, 10:48
Plz remove the on error resume next line in this macro
zyxw1234 wrote:
26 Jul 2020, 11:26
On error resume next line (Professional coder's try to ignore these line in the macro & me too.. sir, it creates issues sometimes that's y)
Can't you use your delete key?
Or have you never actually opened up the VBA editor yourself - you just rely on someone else to do everything for you?
Leif

User avatar
HansV
Administrator
Posts: 78465
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: delete matches by vba (macro correction)

Post by HansV »

What kind of issues does that line cause for you?
Best wishes,
Hans

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: delete matches by vba (macro correction)

Post by zyxw1234 »

This macro doesn't cause any issue
But it's recommended to alway's try to ignore this on error resume next line in the macro

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: delete matches by vba (macro correction)

Post by LisaGreen »

Recommended by whom?
Please quote your sources.
I'd really like to know. This is not a joke!!!

IMHO This is a regular and accepted method of catching errors in VBA.

Lisa

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: delete matches by vba (macro correction)

Post by zyxw1234 »

No Problem Fine
I will use this only
Problem Solved

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: delete matches by vba (macro correction)

Post by LisaGreen »

So what are your sources then????

Lisa

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: delete matches by vba (macro correction)

Post by zyxw1234 »

Means
My Mistake
Sorry for the same
No Sources