I am new to VBA, I am trying my best to explain what I want to do
I need to check sheet 1 and sheet 2 if they have value "AAA" or "BBB" or "CCC" in the row, I want to keep it, if not, delete the entire row
My below code can only help me to remove rows except it contains "AAA" in column Q
i don't know how to add more value like "BBB" & "CCC", if the row have these value, either one, I would like to keep it
how to add more columns to check ? now is only checking in column Q, if I want to check it from column H to R ?
i actually have 10 values (AAA, BBB, CCC .... JJJ) want to keep, do I need to type them out one by one , or there is a method to ask excel to check a list, if any cell in Sheet 1 and Sheet 2 matched with any one from these 10 values, keep the row, otherwise, delete the entire row
the list is locate at Sheet 3 from column A1 :A10
thanks ! my code as below
Sub RemoveCell()
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
With Sheets("Sheet1")
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "Q")
If Not IsError(.Value) Then
If .Value <> "AAA" Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub