ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Row Deletion (https://www.excelbanter.com/excel-programming/424819-row-deletion.html)

SiH23

Row Deletion
 
I'd be most grateful if someone could offer some advice:

I need a macro which will delete all rows with the exception of those
containing the words: Normal WTC Run-on in Column C

Many thanks in advance.








Mike H

Row Deletion
 
Hi,

You weren't particularly clear what you wanted so this will delete all rows
that don;t contain your text and retain those rows that contain the text with
NOTHING ELSE in the cell. Right click your sheet tab, view code and paste
this in and run it.

Sub copyit()
mycolumn = "c" 'Change to suit
Dim MyRange, MyRange1 As Range
LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "1:" & mycolumn & LastRow)
For Each c In MyRange
If UCase(c.Value) < "NORMAL WTC RUN-ON" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

Mike

"SiH23" wrote:

I'd be most grateful if someone could offer some advice:

I need a macro which will delete all rows with the exception of those
containing the words: Normal WTC Run-on in Column C

Many thanks in advance.









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

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