delete rows based on specific criteria

woods2007

Board Regular
Joined
Aug 29, 2007
Messages
57
Hi,

What is the fastest (and safest) way to delete rows based on a criteria which is a part of a cell value, within a specific column?

e.g. cell value is 'temp flexi 12345678' and the criteria for deletion is 'temp flexi '

Cheers
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Use a filter
Cheers,

below is my code:

Dim FinalRow As Long

FinalRow = Cells(Rows.Count, "A").End(xlUp).Row
'
Selection.AutoFilter
ActiveSheet.Range(Cells(1, 1), Cells(FinalRow, 1)).AutoFilter Field:=1, Criteria1:="=temp flexi*"

how do I select the returned rows and delete them?
 
Upvote 0
Why are you using code ?
it is one of many steps in a workbook for a daily morning job that we run. We are looking to take the human element out of the process to minimise the risk of missed steps and output errors (it is a large worksheet with many similarly named columns) and so that any team member can run the job.
 
Upvote 0
Below code loops through col A, and deletes the entire row, if the word "Subtotal" is found.

See if you can adapt

Dim i As Long
Dim LASTROW As Long

LASTROW = Cells(Rows.Count, 1).End(xlUp).Row
' ** Deletes rows where col A value = "Subtotal"
For i = LASTROW To 1 Step -1
If InStr(Range("A" & i).Value, "Subtotal") Then Range("A" & i).EntireRow.Delete Shift:=xlUp

Next i
 
Upvote 0
Below code loops through col A, and deletes the entire row, if the word "Subtotal" is found.

See if you can adapt

Dim i As Long
Dim LASTROW As Long

LASTROW = Cells(Rows.Count, 1).End(xlUp).Row
' ** Deletes rows where col A value = "Subtotal"
For i = LASTROW To 1 Step -1
If InStr(Range("A" & i).Value, "Subtotal") Then Range("A" & i).EntireRow.Delete Shift:=xlUp

Next i
Thanks for the code. I still have the same problem ie. (using your example my criteria value would be 'Sub' within the full string 'Subtotal')

if i was doing it through excel I would use if(left(cell,3)="Sub","Flag for delete","")

any suggestions?
 
Upvote 0
Change this line

If InStr(Range("A" & i).Value, "Subtotal") Then Range("A" & i).EntireRow.Delete Shift:=xlUp

to

If InStr(Range("A" & i).Value, "Sub") Then Range("A" & i).EntireRow.Delete Shift:=xlUp
 
Upvote 0
Change this line

If InStr(Range("A" & i).Value, "Subtotal") Then Range("A" & i).EntireRow.Delete Shift:=xlUp

to

If InStr(Range("A" & i).Value, "Sub") Then Range("A" & i).EntireRow.Delete Shift:=xlUp
That has worked- thanks for bearing with me!
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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