I want to delete rows with specific criteria, for example for column A I want to delete any rows containing "C", in column E I want to delete rows containing "AB", column F I want to delete rows containing "CE", in column G I want to delete rows containing "ZZ". I've tried a code that worked but only for 1 column & 1 criteria but I'm trying to create a macro to delete multiple columns with different criteria. Here's the code I tried and worked but I need it for multiple columns:
Sub Union_Example()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim rng As Range
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
'We check the values in the A column in this example
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
If .Value = "C" Then
'This will delete each row with the Value "C"
'in Column A, case sensitive.
If rng Is Nothing Then
Set rng = .Cells
Else
Set rng = Application.Union(rng, .Cells)
End If
End If
End If
End With
Next Lrow
End With
'Delete all rows in one time
If Not rng Is Nothing Then rng.EntireRow.Delete
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
please help.
cb10
Bookmarks