Deleting Certain Rows Using InStr

himalayan

New Member
Joined
Nov 12, 2014
Messages
5
Hi there,

I'm trying to delete specific rows in a range that do not contain the value input by a user, almost like a filter:

User clicks command button and enters value -> Range ("C2:C25") is queried for the value -> Any cells that do not contain the value are deleted (as a whole row)

The problem I am having is how the loop controls the deleting of rows, which is forcing it to miss out rows if there are to be two deleted rows in succession. I am hoping someone can give me an idea as to how I can get around this. I've got to the point where my mind has stopped working because I've been fussing about it for so long :LOL:

Code:
Do Until CurrentRow = LastRow + 1If InStr(1, Range(FilterField & CurrentRow), FilterValue, vbTextCompare) Then
CurrentRow = CurrentRow + 1
Else
.Rows(CurrentRow).EntireRow.Delete
CurrentRow = CurrentRow + 1
End If
Loop
End With

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
you need to delete from the last row upover

Dim LR As Integer

LR = Cells(Rows.Count, "a").End(xlUp).Row
For i = LR To 2 Step -1
If Range("a" & i) = "" Then
Range("a" & i).EntireRow.Delete
End If
Next i
 
Upvote 0

Forum statistics

Threads
1,216,131
Messages
6,129,066
Members
449,485
Latest member
greggy

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