Hi Guys,
I'am trying to write a small script to delete the "Cancelled" word in a column and keep the "Shipped" and "delivered" words.
Below is the code
However, when I run the script get an error "Application Defined or object defined error - Run time error 1004" in the 4th line
lastrow1 = Cells(Rows.Count, st).End(xlUp).Row
Please reply and help me in finding out the issue in this script.
I'am trying to write a small script to delete the "Cancelled" word in a column and keep the "Shipped" and "delivered" words.
Below is the code
Code:
Sub removecancelled()
Dim st As String, i As Integer, lastrow1 As Long
st = WorksheetFunction.Match("Status", Range("1:1"), 0)
lastrow1 = Cells(Rows.Count, st).End(xlUp).Row
For i = lastrow1 To 2 Step -1
If Cells(i, st) = "cancelled" Then
Cells(i, st).EntireRow.Delete
End If
Next i
However, when I run the script get an error "Application Defined or object defined error - Run time error 1004" in the 4th line
lastrow1 = Cells(Rows.Count, st).End(xlUp).Row
Please reply and help me in finding out the issue in this script.
Last edited: