Excel VBA to Delete Rows with Zeros, Type Mismatch Error

theteerex

Board Regular
Joined
Mar 2, 2018
Messages
102
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.

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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If the cell value contains a formula error, you will get that "Type Mismatch" error.

Perhaps modify your formulas to not error or wrap them in an IFERROR function e.g.;
=IFERROR(your_formula_here, 0)
 
Upvote 0
If the cell value contains a formula error, you will get that "Type Mismatch" error.

Perhaps modify your formulas to not error or wrap them in an IFERROR function e.g.;
=IFERROR(your_formula_here, 0)
Which formulas are you talking about?
As far as I can tell, there is no type mismatch.
Are you suggesting I wrap all the formulas in the
Code:
=IFERROR
?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top