ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro Help / Question (https://www.excelbanter.com/excel-programming/287282-macro-help-question.html)

Ed[_14_]

Macro Help / Question
 
I have a macro that deletes the entire row if it matches certain criteria.
What I need help with is I need to delete rows that DO NOT MATCH specfic
criteria. Instead of "Like" I need a "not like" or similar. I want to delete
the row if it does not contain 591119.

T.I.A.
Ed


Sub DeleteRow2()
Dim LastRow As Long
Dim i As Long
LastRow = Range("A6536").End(xlUp).Row
For i = LastRow To 1 Step -1

If Range("S" & i).Value Like "VIP CHRG" Then
Range("S" & i).EntireRow.Delete
End If
Next 'i

For i = LastRow To 1 Step -1
If Range("S" & i).Value Like "EXCHANGE" Then
Range("S" & i).EntireRow.Delete
End If
Next 'i

End Sub






Don Guillett[_4_]

Macro Help / Question
 
untested with yours but try
If not( Range("S" & i).Value Like "VIP CHRG") Then


--
Don Guillett
SalesAid Software

"Ed" wrote in message
...
I have a macro that deletes the entire row if it matches certain criteria.
What I need help with is I need to delete rows that DO NOT MATCH specfic
criteria. Instead of "Like" I need a "not like" or similar. I want to

delete
the row if it does not contain 591119.

T.I.A.
Ed


Sub DeleteRow2()
Dim LastRow As Long
Dim i As Long
LastRow = Range("A6536").End(xlUp).Row
For i = LastRow To 1 Step -1

If Range("S" & i).Value Like "VIP CHRG" Then
Range("S" & i).EntireRow.Delete
End If
Next 'i

For i = LastRow To 1 Step -1
If Range("S" & i).Value Like "EXCHANGE" Then
Range("S" & i).EntireRow.Delete
End If
Next 'i

End Sub








mudraker[_80_]

Macro Help / Question
 
Add NOT

If Not Range("S" & i).Value Like "VIP CHRG" Then



If Not Range("S" & i).Value Like "EXCHANGE" Then


---
Message posted from http://www.ExcelForum.com/


Tom Ogilvy

Macro Help / Question
 
if instr(1,Range("S" & i).Text,"591119",vbTextCompare) = 0 then
Range("S" & i).entireRow.Delete
End if

--
Regards,
Tom Ogilvy


Ed wrote in message
...
I have a macro that deletes the entire row if it matches certain criteria.
What I need help with is I need to delete rows that DO NOT MATCH specfic
criteria. Instead of "Like" I need a "not like" or similar. I want to

delete
the row if it does not contain 591119.

T.I.A.
Ed


Sub DeleteRow2()
Dim LastRow As Long
Dim i As Long
LastRow = Range("A6536").End(xlUp).Row
For i = LastRow To 1 Step -1

If Range("S" & i).Value Like "VIP CHRG" Then
Range("S" & i).EntireRow.Delete
End If
Next 'i

For i = LastRow To 1 Step -1
If Range("S" & i).Value Like "EXCHANGE" Then
Range("S" & i).EntireRow.Delete
End If
Next 'i

End Sub









All times are GMT +1. The time now is 07:35 AM.

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