delete rows between a range of numbers

excelnoobhere

Board Regular
Joined
Mar 11, 2019
Messages
61
I have the following code that deletes the entire row if its value is 900.

Code:
  Sub RemoveRows900()

Dim i As Long


i = 1


Do While i <= ThisWorkbook.ActiveSheet.Range("AA7:AA1000").CurrentRegion.Rows.Count


    If InStr(1, ThisWorkbook.ActiveSheet.Cells(i, 1).Text, "900", vbTextCompare) > 0 Then
        ThisWorkbook.ActiveSheet.Cells(i, 1).EntireRow.Delete
    Else
        i = i + 1
    End If


Loop


End Sub

I want the code to be able to remove any row that is between 001 to 140 with the addition of 900

but I'm keeping 001 and 140

only the numbers in between
for example: if my row contain 141 keep, 140 keep, 139 delete, 000 keep, 001 keep 002 delete, 900 delete and so on

thanx in advance
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I got it

Code:
Sub Delete_001_140()
    Dim N As Long, i As Long
    N = Cells(Rows.Count, "AA").End(xlUp).Row
    Application.ScreenUpdating = False
    For i = N To 1 Step -1
        v = Cells(i, "AA").Value
        If v > 0 And v < 140 Then
            Cells(i, "AA").EntireRow.Delete
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
.
Great job !

Curious ... how did you cover the 900, 901, 902, etc ?
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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