Code Run-time Error '13

R

Ron

Hello all, I'm having problems with the code below. The purpose of
the code is to check column A cell content for "Delete" which is
populated by a vlookup formula. The problem is if an account is not
found then the cell is populated with #N/A and causes a run-time error
'13: type mismatch. Any ideas on correcting this? Appreciate your
assistance, Ron


Sub DeleteSTBAccounts()
Dim RowNdx As Long
Dim LastRow As Long

application.ScreenUpdating = False
ActiveSheet.Rows.Hidden = False


LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row


For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A") = "Delete" Then
Rows(RowNdx).EntireRow.Delete
End If

Next RowNdx
range("A1").Select
End Sub
 
J

JLGWhiz

It might not like the redundancy in this line:

Rows(RowNdx).EntireRow.Delete

try:


Rows(RowNdx).Delete
 
S

stanleydgromjr

Ron,

Try:


Code:
--------------------


Option Explicit
Sub DeleteSTBAccounts()
Dim RowNdx As Long
Dim LastRow As Long
Application.ScreenUpdating = False
ActiveSheet.Rows.Hidden = False
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If IsError(Cells(RowNdx, "A")) Then
'Do nothing
ElseIf Cells(RowNdx, "A") = "Delete" Then
Rows(RowNdx).EntireRow.Delete
End If
Next RowNdx
Range("A1").Select
End Sub


--------------------



Have a great day,
Stan
 
R

Ron

Hi JLGWhiz, the error is coming on this line.... If Cells(RowNdx,
"A") = "Delete" Then. I made the suggested change, but still got the
error. Thanks, Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top