Delete row macro

  • Thread starter Thread starter Esrei
  • Start date Start date
E

Esrei

This is the whole macro:

My range is A3:D500

I want to delete the row if the value in D is 0
At the moment I get a "Tipe mismatch" error

Please help????

Sheets("SALES SUMMARY").Select
Sheets("SALES SUMMARY").Copy After:=Sheets(26)
Range("A3:M571").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=-15
Range("A3").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Columns("C:J").Select
Selection.Delete Shift:=xlToLeft
Columns("E:K").Select
Selection.Delete Shift:=xlToLeft
Range("F10").Select
Dim lastrow As Long
Dim row_index As Long
Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Cells(row_index, "D").Value = 0 Then
Rows(row_index).Delete
End If
Next
Application.ScreenUpdating = True
End Sub
 
Do you know at which line your code is bugging out? (If you press debug when the error occurs, it will be highlighted in yellow)
 
The code is bugging out on the line that states:
If Cells(row_index, "D").Value = 0 Then
-----Original Message-----
Do you know at which line your code is bugging out? (If
you press debug when the error occurs, it will be
highlighted in yellow)
 
Hi
do you have error values in this column (e.g. #NA or #VALUE). If yes
try
For row_index = lastrow - 1 To 1 Step -1
if not iserror(Cells(row_index, "D").Value) then
If Cells(row_index, "D").Value = 0 Then
Rows(row_index).Delete
End If
end if
Next
 
Back
Top