Exclude the only one value and delete all values in vba excel

mayaa_mmm

Board Regular
Joined
Jul 30, 2014
Messages
54
Office Version
  1. 2010
Platform
  1. Windows
When i apply filter , it should uncheck only John and apply filter to all the values except john and delete the rows till last value


MarkName
80John
20Maya
30John
40Peter

In my report , John is the standard person. But Names daily will get change. I need to delete the rows except John.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You can try this to see if it is what you want.

VBA Code:
Sub t()
With ActiveSheet.UsedRange
    .AutoFilter 2, "<>John"
    .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
ActiveSheet.AutoFilterMode = False
End Sub
 
Upvote 0
You can try this to see if it is what you want.

VBA Code:
Sub t()
With ActiveSheet.UsedRange
    .AutoFilter 2, "<>John"
    .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
ActiveSheet.AutoFilterMode = False
End Sub


It works but delete all the rows ,keep the header alone

I have written the logic like this
ActiveSheet.Range("M:M").AutoFilter Field:=13, Criteria1:="<>John"
but Error is thrown in the logic
 
Upvote 0
It works but delete all the rows ,keep the header alone

I have written the logic like this
ActiveSheet.Range("M:M").AutoFilter Field:=13, Criteria1:="<>John"
but Error is thrown in the logic


Sorry for the trouble.
Your logic is working for me, I fixed it.

Thank you
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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