Deletes rows that do not have a specific word in a specific column

FireRulerX

New Member
Joined
Aug 10, 2010
Messages
5
Here is the code I am using but can not make it viable to a specifc column.


Sub Delete_Rows()
' This macro deletes all rows on the active worksheet
' that do not have Versaold in column F.
Dim Rng As Range, cell As Range, del As Range
Dim strCellValue As String
Set Rng = Intersect(Range("F2:F1000"), ActiveSheet.UsedRange)
For Each cell In Rng

strCellValue = (cell.Value)
If InStr(strCellValue, "VERSACOLD") > 0 Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.DELETE
End Sub


Thanks A lot
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Code:
Sub Delete_Rows2()
    ' This macro deletes all rows on the active worksheet
    ' that do not have Versaold within the row.
    Dim Lastrow As Long
    
    Application.ScreenUpdating = False
    
    Lastrow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    For r = Lastrow To 1 Step -1
        If Rows(r).Find("VERSACOLD", LookAt:=xlPart, MatchCase:=False) Is Nothing Then Rows(r).Delete
    Next r
    
    Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0
The code worked good but the problem is I need the code to only find the word versacold in column F as there could be the word versacold in column A or B and I want them delete too.

Cheers
 
Upvote 0
Maybe:

Code:
Option Compare Text
Sub delNotFound()
    Dim searchCol, searchParam, headerRow, lastRow
    searchCol = "F"
    searchParam = "versacold"
    headerRow = 2
    lastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For i = lastRow To headerRow + 1 Step -1
        If InStr(Cells(i, searchCol), searchParam) = 0 Then Rows(i).EntireRow.Delete
    Next i
End Sub
 
Upvote 0
What you are saying is contradictory to me. I don' t understand.

This...
I need the code to only find the word versacold in column F

Is the opposite of this...
there could be the word versacold in column A or B and I want them delete too

Maybe you could give an example.
 
Upvote 0
smiley.jpg


If I use these smileys as an example I would want everything but row 3,4, and 6 non-delete as they have the blue question mark smiley in the 4th column. I would want all the others deleted even though some of them contain blue question smileys. so if you use the word versacold to represent blue smiley's question mark that is what I mean hope this helps.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

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