this code wont work, it doesnt take last row from AO column, and it wont erase the rows. Can someone help?
Sub DeleteRowsWithZeroOrBlankInColumnA()
Dim ws As Worksheet
Dim cell As Range
Dim lastRow As Long
On Error Resume Next ' Ignore errors temporarily
' Specify the worksheet
Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
If Not ws Is Nothing Then
' Determine the last row in column AO
lastRow = ws.Cells(ws.Rows.Count, AO).End(xlUp).Row
Debug.Print lastRow
' Loop through each cell in column AO from the last row to the first row
For i = lastRow To 1 Step -1
' Check if the value in column AO is zero or blank
If ws.Cells(i, "AO").Value = 0 Or ws.Cells(i, "AO").Value = "" Then
' Delete the entire row if the condition is met
ws.Rows(i).EntireRow.Delete
End If
Next i
Else
Debug.Print "Worksheet not found." ' Print message if worksheet is not found
End If
On Error GoTo 0 ' Reset error handling
End Sub
i try to change code for last row with 43 unstead AO, different variants of deleting row, but it wont work