For the code below, I get a type mismatch error on the line highlighted in red.
The code runs down a defined column and when it finds a zero, deletes the entire row.
What is the line missing? Initially it worked and then it stopped working.
The code runs down a defined column and when it finds a zero, deletes the entire row.
What is the line missing? Initially it worked and then it stopped working.
Code:
Option Explicit
Sub CleanUp()
Dim sh As Worksheet
Dim Oppo As Long
Dim CheckLoop As Long
Dim RowCount As Long
Dim DelRng As Range
Set sh = ThisWorkbook.Sheets("Database")
With sh
RowCount = .Cells(.Rows.Count, "C").End(xlUp).Row [COLOR=#008000]' get last row with data in column "C"[/COLOR]
For CheckLoop = RowCount To 2 Step -1
[COLOR=#008000] 'Debug.Print CheckLoop.Row[/COLOR]
[COLOR=#ff0000][B] If .Range("C" & CheckLoop).Value = 0 Then ' <== modified this line[/B][/COLOR]
If Not DelRng Is Nothing Then
Set DelRng = Application.Union(DelRng, .Rows(CheckLoop))
Else
Set DelRng = .Rows(CheckLoop)
End If
End If
Next CheckLoop
End With
[COLOR=#008000]' if range object is not empty >> delete entire rows at 1-line[/COLOR]
If Not DelRng Is Nothing Then DelRng.Delete
End Sub