Delete all line that are not ".XX"

Jeeremy7

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

I'm having trouble with a macro i'm trying to create.
Somoene already helped me here with a macro I was trying to do which was deleting all line that are not ending with .02. I modified it to add the .12 and .22 condition.
Now I would like the macro to delete everything that is not .XX (by .XX i mean anything)
Is that possible or I would need to enumerate every .XX there is in my sheet (There's quite a lot)

Thanks a lot !

Here's the original macro if it's easier for you to work with :)

VBA Code:
Dim lr As Long

Dim r As Long

Dim Rng As Range



Application.EnableEvents = False

Application.ScreenUpdating = False

Application.Calculation = xlCalculationManual

' Find last row with data in column A

lr = Cells(Rows.Count, "A").End(xlUp).Row

' Loop through all rows backwards and delete ones not meeting conditions

For r = lr To 1 Step -1

If Right(Cells(r, "A"), 3) <> ".02" And Right(Cells(r, "A"), 3) <> ".12" And Right(Cells(r, "A"), 3) <> ".22" Then

If Rng Is Nothing Then Set Rng = Rows(r) Else Set Rng = Union(Rng, Rows(r))

End If

Next r

If Not Rng Is Nothing Then Rng.Delete



Application.Calculation = xlCalculationAutomatic

Application.ScreenUpdating = True

Application.EnableEvents = True
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Instead of a lot of = or <> you could use the test

aString Like "*.??"

Which will test if aString ends in a dot followed by any two characters.
 
Upvote 0
So would it be
If Right(Cells(r, "A"), 3) aString Like "*.??" Then
 
Upvote 0
No hehe I wanted to delete everything but the .XX :LOL:

Sorry i'm still practicing my english might have phrased wrong
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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