Hello,
i need a vba code that will delete all rows above the cell that contains specific string, is that possible? I got this one, but it will only delete two rows above.
Thanks.
Tomas
i need a vba code that will delete all rows above the cell that contains specific string, is that possible? I got this one, but it will only delete two rows above.
Code:
Dim x
For x = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row To ActiveCell.Row Step -1
If Cells(x, 1) = "Slovakia" Then 'If we find this text
Cells(x - 1, 1).EntireRow.delete 'Delete the row above it
Cells(x - 2, 1).EntireRow.delete 'Delete the row 2 rows above it
x = x - 2
'Delete blank rows
ElseIf Cells(x, 1) = vbNullString Then Cells(x, 1).EntireRow.delete
'Optional delete rows that contain "File looks like ..."
'ElseIf Cells(x, 1) = "File looks like it is not encrypted. Skipping ..." Then Cells(x, 1).EntireRow.Delete
'ElseIf Cells(x, 1) = "File could not be decrypted properly. Skipping ..." Then Cells(x, 1).EntireRow.Delete
End If
Next x
Thanks.
Tomas