Hi,
I've just received a reply on how to delete all rows where the value isn't "NNN" in column AF which worked perfectly.
Can I push this one step further and ask for a specific row (row 18 in this instance) to be ignored from this macro?
Previous solution which worked was
Sub DeleteRowsNotNNN()
Dim ws As Worksheet, lastRow As Long, i As Long
' Set the worksheet
Set ws = ThisWorkbook.Sheets("REP500")
' Find the last row in the sheet based on column AF
lastRow = ws.Cells(ws.Rows.Count, "AF").End(xlUp).Row
' Loop through the rows from the last to the first to avoid skipping rows
For i = lastRow To 1 Step -1
' Check if the value in column AF is not "NNN"
If ws.Cells(i, "AF").Value <> "NNN" Then
' Delete the entire row if value is not "NNN"
ws.Rows(i).Delete
End If
Next i
End Sub
Thanks
Tom
I've just received a reply on how to delete all rows where the value isn't "NNN" in column AF which worked perfectly.
Can I push this one step further and ask for a specific row (row 18 in this instance) to be ignored from this macro?
Previous solution which worked was
Sub DeleteRowsNotNNN()
Dim ws As Worksheet, lastRow As Long, i As Long
' Set the worksheet
Set ws = ThisWorkbook.Sheets("REP500")
' Find the last row in the sheet based on column AF
lastRow = ws.Cells(ws.Rows.Count, "AF").End(xlUp).Row
' Loop through the rows from the last to the first to avoid skipping rows
For i = lastRow To 1 Step -1
' Check if the value in column AF is not "NNN"
If ws.Cells(i, "AF").Value <> "NNN" Then
' Delete the entire row if value is not "NNN"
ws.Rows(i).Delete
End If
Next i
End Sub
Thanks
Tom