ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Deleting a Row if it contains a specific word (https://www.excelbanter.com/excel-discussion-misc-queries/128834-deleting-row-if-contains-specific-word.html)

Steve Madsen

Deleting a Row if it contains a specific word
 
I want to develop a macro that will search through a worksheet and delete any
row(s) that contains the word "Step". The word could occur anywhere within
any cell in the row.

Thanks for any help offered.

Ron de Bruin

Deleting a Row if it contains a specific word
 
Hi Steve

Look here for a few ways
http://www.rondebruin.nl/delete.htm

Try

Sub Example1()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

Firstrow = ActiveSheet.UsedRange.Cells(1).Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1

With ActiveSheet
.DisplayPageBreaks = False
For Lrow = Lastrow To Firstrow Step -1

If Application.WorksheetFunction.CountIf(.Rows(Lrow), "Step") 0 Then
.Rows(Lrow).Delete
End If

Next
End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Steve Madsen" <Steve wrote in message ...
I want to develop a macro that will search through a worksheet and delete any
row(s) that contains the word "Step". The word could occur anywhere within
any cell in the row.

Thanks for any help offered.



All times are GMT +1. The time now is 12:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com