Runtime Error 13 in my code

WolfLarsen85

New Member
Joined
Apr 25, 2016
Messages
17
I am getting a run time error 13 in my code between the **. Can anyone out there see why? For some reason the code will run and do what I want, but then spit out the error. Any help will be appreciated.

Sub Recon()
Dim i As Integer


finalrow = Sheets("Reconciliation").Range("A500").End(xlUp).Row


Sheets("Reconciliation").Activate
Sheets("Reconciliation").Range("D2:D500").ClearContents


Range("D2:D500") = "=IFERROR(INDEX($F$2:$F$500,MATCH(1,INDEX((B2 = $G$2:$G$500)*(C2=$H$2:$H$500),0,1),0)), Not Matched)"


Last = Cells(Rows.Count, "D").End(xlUp).Row
For i = Last To 1 Step -1
**If (Cells(i, "A").Value) = 0 And (Cells(i, "D").Value) = 0 Then**
Cells(i, "A") = "Delete"
End If
Next i


Last = Cells(Rows.Count, "D").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "A").Value) = "Delete" Then
Cells(i, "A").EntireRow.Delete
End If
Next i




End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
The error can be because you have a cell in A or D with error #N/A, #!DIV/0!, #¡REF! etc

Review the results of the formulas
 
Upvote 0
Yes, I do have cells returning errors, thank you for responcing. How do I set up the IsError function in that code? Do I have to restructure it?

Last = Cells(Rows.Count, "D").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "A").Value) = "" And (Cells(i, "D").Value) = IsError("D2:D500") Then
Cells(i, "A") = "Delete"
End If
Next i

The error can be because you have a cell in A or D with error #N/A, #!DIV/0!, #¡REF! etc

Review the results of the formulas
 
Upvote 0
It's Cells(i, "A").Value and Cells(i, "D").Value you need to check for errors.

What do you want to happen when you find errors in those cells?
 
Upvote 0
I want those rows that meet both criteria for "A" and "D" deleted. Bascially if cells in column A cells are blank and column D has an error, delete rows.
 
Upvote 0
I structured the code to say "Delete" in those blank column A cells so that I can used 2 criteria so other cells that I don't want deleted aren't.
 
Upvote 0
In that block, bascially what I am doing is if column D has an error and column A is blank then insert the word "Delete" into the blank column A cells.

The second code block then looks for "Delete" in the column A cells and deletes the entire row.

The code actually works, but I get that runtime error message because the column D cell are returning an error.


It's Cells(i, "A").Value and Cells(i, "D").Value you need to check for errors.

What do you want to happen when you find errors in those cells?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
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