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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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