Formula stopped working.

corbie82

New Member
Joined
Jun 7, 2014
Messages
23
So this worked fine a few months which was the last time i used it but every time i run it now it says

Run-time error 13
Type Mismatch




Sub DeleteRows()
Dim iLastRow As Long
Dim i As Long
iLastRow = Cells(Rows.Count, "G").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Cells(i, "G").Value = "0" Then
Rows(i).delete
End If
Next i
End Sub

It highlights an issue with this row
If Cells(i, "G").Value = "0" Then

Any ideas ?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I concur with ParamRay, an error of that type causes your code to fail.

You can se this to delete those rows as well;
Code:
Sub DeleteRows()Dim iLastRow As Long
Dim i As Long
On Error Resume Next
iLastRow = Cells(Rows.Count, "G").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Cells(i, "G").Value = "0" Then
Rows(i).Delete
End If
Next i
End Sub

OR if you wish to identify the error and have the option to investigate it then;

Code:
Sub DeleteRows()Dim iLastRow As Long
Dim i As Long
On Error GoTo ErrHandle
iLastRow = Cells(Rows.Count, "G").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Cells(i, "G").Value = "0" Then
Rows(i).Delete
End If
Next i
Exit Sub
ErrHandle:
If MsgBox("Your error lies in cell " & Cells(i, "G").Address & vbNewLine & "Goto error cell?", vbYesNo + vbCritical, "Error!") = vbYes Then
Cells(i, "G").Select
Else
'Do Nothing & Exit Sub
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,884
Messages
6,127,565
Members
449,385
Latest member
KMGLarson

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