Error 13, Type Mismatch...Why????

Desu Nota from Columbus

Well-known Member
Joined
Mar 17, 2011
Messages
556
Code:
For i = 2 To 10000
    If Cells(i, 6).Value = 0 Then    `error on this line
        Cells(i, 6).Delete Shift:=xlUp
    End If
Next i

I tried using

Range("F" & i).Value = 0 Then

and it didn't work either.

What am I not understanding?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
What have you dimmed i as?

BTW, that is not going to work, you will have to work backwards through the range with a Step -1
For just one line of code, I would personally use a single-line If instead of the Block If.
 
Last edited:
Upvote 0
Code:
Sub test()
Dim i As Long
Application.ScreenUpdating = False
    For i = 10000 To 2 Step -1
        If Cells(i, 6) = 0 Then Cells(i, 6).Delete
    Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Is it possible that Cells(i,6) contains an error value (e.g. #DIV/0)? That would cause a type mismatch (= doesn't handle errors).

If that's the case this would be one way to fix it.

Code:
If CStr(Cells(i, 6).Value) = "0" Then
 
Upvote 0
i was defined as an Integer,

yes it was possible that there was an error, and i corrected this by changing a formula further up my in my code (now there are only text and 0's possible in the range)

I will post back once i check
 
Upvote 0
Thanks to you both!

I forgot I needed to step back through the range.

Why does i (changed to r) have to be defined as a long? Isn't the range Cells(r, 26) dealing with integers small enough to cover what i need?

An integer is defined to be accepted up to 2^32 (aka much less than 1000)...correct?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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