Search for a word and delete the entire row.

mdennis624

New Member
Joined
Feb 17, 2002
Messages
16
For Excel 97: I need a macro to search a column (B) for cells that might contain a specific word ("space")within the contents of the cells. If the cell contains the word ("space"), delete the entire row. ie. If the cell contents = "This is a space", the macro would delete the entire row for any occurence of the word "space" in the column search.
This message was edited by mdennis624 on 2002-02-18 19:23
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
This code assumes column A; modify as needed.

Sub DeleteSpaceRows()
Dim iRow As Long
For iRow = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Cells(iRow, 1) = "space" Then Rows(iRow).Delete
Next iRow
End Sub

Tom Urtis
 
Upvote 0
Dennis,

I re-read your post and noticed after my first reply that the word "space" might be in a string of words in a single cell.

Try this macro instead then, it avoids loops by replacing "space" with nothing, hence a blank cell, and then deletes the rows with a blank cell in column A. Modify for column range.

Sub DeleteSpace()
With Columns("A:A")
.Replace What:="*space*", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
End Sub

HTH

Tom Urtis
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,424
Members
448,896
Latest member
MadMarty

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