Delete Rows Starting With Specified Number

ashah

New Member
Joined
Jul 30, 2013
Messages
3
I have found this code from another thread on this forum for deleting the row that contains a cell (in column B) that begins with a specific letter. I would like to perform the same task for numbers. Simply replacing the C* with 2* has not worked.

Any help is greatly appreciated.

Sub DeleteRows()
Dim i As Long
i = Range("B" & Rows.Count).End(xlUp).Row
With Range("B1:B" & i)
If Application.WorksheetFunction.CountIf(Columns(2), "C*") > 0 Then
.AutoFilter field:=1, Criteria1:="C*"
.Offset(1).Resize(.Rows.Count - 1, 1).EntireRow.Delete
.AutoFilter
End If
End With
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Not thoroughly tested:
Code:
Sub DelRows()
With Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row)
    .Replace "2*", vbNullString, xlWhole, xlByRows, False
    On Error Resume Next
    .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    On Error GoTo 0
End With
End Sub
 
Upvote 0
Not thoroughly tested:
Code:
Sub DelRows()
With Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row)
    .Replace "2*", vbNullString, xlWhole, xlByRows, False
    On Error Resume Next
    .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    On Error GoTo 0
End With
End Sub

Works perfectly, thanks!
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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