I want to delete rows based on cell value that contains the words "upg" or "upgrade" inside the cell. when this word are there, it is not the only words inside the cell.
Here is part of my code, that not deletes anything:
Sub DeleteValues()
Dim i As Integer
Dim MFG_wb As Workbook
Dim Dep As Integer
Set MFG_wb = Workbooks.Open _
("C:\Users\rosipov\Desktop\eliran\MFG - GSS\MFG Daily\Fast Daily " & Format(Now(), "ddmmyy") & ".xlsx", _
UpdateLinks:=False, IgnoreReadOnlyRecommended:=True)
MFG_wb.Sheets("Aleris").Activate
Dep = MFG_wb.Sheets("Aleris").Range("B2").End(xlDown).Row
For i = Dep To 2 Step -1
Cells(i, 2).Select
If Not (Selection.Value = "& upg &" Or Selection.Value = "*& upgrade &*") Then
Rows(i).Delete
End If
Next i
End Sub
Here is the problem:
For i = Dep To 2 Step -1
Cells(i, 2).Select
If Not (Selection.Value = "& upg &" Or Selection.Value = "*& upgrade &*") Then
Rows(i).Delete
End If
Next i
Use INSTR():
For i = Dep To 2 Step -1
If Instr(MFG_wb.Sheets("Aleris").Cells(i, 2).Value,"upg")>0 Or Instr(MFG_wb.Sheets("Aleris").Cells(i, 2).Value,"upgrade") >0 Then
MFG_wb.Sheets("Aleris").Rows(i).Delete
End If
Next i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With