Dinesh_Excel
Member
Hi
I would like to know how to delete multiple rows containing different text (sample below) which I can include in my macro.
Colunm B contains text : "Invoice ", " Payment" and PO
Column C contains text : "Germany" , "Poland" and UK
Column D contains text : " Paid" ," outstanding" and Overdue
Column E contains text : " Scope" ,"not in scope"
The rows should be deleted upon satisfying the above criteria.
Please help me on extending the below code
Sub Test()
Dim ws As WorksheetDim lastRow AsLong, i AsLongDim value AsString
Set ws = ActiveWorkbook.Sheets("*Name of Worksheet")
lastRow = ws.Range("D"& ws.Rows.Count).End(xlUp).Row
' Evaluate each row for deletion.' Go in reverse order so indexes don't get messed up.
For i = lastRow To2Step-1
value = ws.Cells(i,4).Value ' Column D value.
' Check if it contains one of the keywords.If Instr(value,"INVOICE")=0 _And Instr(value,"PAYMENT")=0 _And Instr(value,"P.O.")=0 _Then
' Protected values not found. Delete the row.
ws.Rows(i).Delete
EndIfNext
EndSub
Sub MultiDelete()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
For Each cell In Range("A4:A200")
Select Case cell.Value
Case "Name1", "Name2", "Name3"
cell.EntireRow.Delete
End Select
Next cell
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
I would like to know how to delete multiple rows containing different text (sample below) which I can include in my macro.
Colunm B contains text : "Invoice ", " Payment" and PO
Column C contains text : "Germany" , "Poland" and UK
Column D contains text : " Paid" ," outstanding" and Overdue
Column E contains text : " Scope" ,"not in scope"
The rows should be deleted upon satisfying the above criteria.
Please help me on extending the below code
Sub Test()
Dim ws As WorksheetDim lastRow AsLong, i AsLongDim value AsString
Set ws = ActiveWorkbook.Sheets("*Name of Worksheet")
lastRow = ws.Range("D"& ws.Rows.Count).End(xlUp).Row
' Evaluate each row for deletion.' Go in reverse order so indexes don't get messed up.
For i = lastRow To2Step-1
value = ws.Cells(i,4).Value ' Column D value.
' Check if it contains one of the keywords.If Instr(value,"INVOICE")=0 _And Instr(value,"PAYMENT")=0 _And Instr(value,"P.O.")=0 _Then
' Protected values not found. Delete the row.
ws.Rows(i).Delete
EndIfNext
EndSub
Sub MultiDelete()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
For Each cell In Range("A4:A200")
Select Case cell.Value
Case "Name1", "Name2", "Name3"
cell.EntireRow.Delete
End Select
Next cell
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub