HELP - Deleting rows in Excel with Macro

benjamint

Board Regular
Joined
Jun 24, 2009
Messages
114
I want to delete all the data in of a row if column B contains value that is below 80900 and/or starts with I.
Is there anyone who knows how to create a macro for this?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try

Code:
Sub DelRow()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    With Range("B" & i)
        If IsNumeric(.Value) Then
            If .Value < 80900 Then Rows(i).Delete
        Else
            If Left(.Value, 1) = "I" Then Rows(i).Delete
        End If
    End With
Next i
End Sub
 
Upvote 0
Another option (assuming heading in row 1)

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Del_Rws()<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Range("B1", Range("B" & Rows.Count).End(xlUp))<br>        .AutoFilter Field:=1, Criteria1:="<80900", _<br>            Operator:=xlOr, Criteria2:="=I*"<br>        <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>        .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete<br>        <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0<br>        .AutoFilter<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Last edited:
Upvote 0
Try

Code:
Sub DelRow()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    With Range("B" & i)
        If IsNumeric(.Value) Then
            If .Value < 80900 Then Rows(i).Delete
        Else
            If Left(.Value, 1) = "I" Then Rows(i).Delete
        End If
    End With
Next i
End Sub

Thank you so much!!! This worked for me. This was exactly what I was looking for.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

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