delete entire row if value

sparky101747

New Member
Joined
Feb 10, 2011
Messages
43
I need to delete the entire row if the value does not end with 000 or 500. I have varying number of rows week to week and the column (W) may or may not contain blank cells.

W
750000
600000

550250 <-----Delete entire row
350500
150500
250350 <------Delete entire row

Thank You in advance.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Using column A for example:
Excel Workbook
A
1750000
2600000
3
4550250
5350500
6150500
7250350
Sheet1
Excel 2003

Try:
Rich (BB code):
Option Explicit
    
Sub exa()
Dim lRow As Long, i As Long
    
    lRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    For i = lRow To 1 Step -1
        If Not Right(Cells(i, "A").Text, 3) Like "000" And Not Right(Cells(i, "A").Text, 3) Like "500" Then
            Rows(i).Delete xlShiftUp
        End If
    Next
    
End Sub
Hope that helps,

Mark
 
Upvote 0
Try

Code:
Sub DelW()
Dim LR As Long, i As Long
LR = Range("W" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    With Range("W" & i)
        If Right(.Value, 3) <> "000" And Right(.Value, 3) <> "500" Then .EntireRow.Delete
    End With
Next i
End Sub
 
Upvote 0
Try this

Code:
Sub DelRow()
    Columns("W:W").Select
    For Each objCell In Selection
        If (objCell.Value2 Mod 500) <> 0 Then
            objCell.EntireRow.Delete
        End If
    Next
End Sub
 
Upvote 0
Thanks to everyone that replied, I used GTO's But added "And Not Right(Cells(i, "W").Text, 3) Like " "" to the end because it was deleting the rows with blank cells also so it looks like this now:

Code:
Option Explicit
 
Sub exa()
Dim lRow As Long, i As Long
 
    lRow = Cells(Rows.Count, "A").End(xlUp).Row
 
    For i = lRow To 1 Step -1
        If Not Right(Cells(i, "W").Text, 3) Like "000" And Not Right(Cells(i, "W").Text, 3) Like "500" And Not Right(Cells(i, "W").Text, 3) Like "" Then
            Rows(i).Delete xlShiftUp
        End If
    Next
 
End Sub

It seems to work, Is the correct way or is there another way?
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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