Error at runtime '13'

Asked

Viewed 266 times

1

I am creating a macro to erase the values of the cell that contains #N/D, but it gives me presents (Error at runtime '13')

When I put #N/A the code works.

Someone can help me solve the problem?

 Private Sub CommandButton1_Click()
'percorre da linha 2 até a última preenchida em A
   For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    'se em B for #N/D
    If Cells(i, 2) = "#N/D" Then
    'apaga conteúdo de A
    Cells(i, 2).ClearContents
    End If
  'próxima linha
 Next i

End Sub
  • You can format the text of your question so you can get better at understanding.

  • @Doctor stephenstrange got better ?

  • It was very Show!!!

  • @Phd stephenstrange excel does not accept #N/D as a value, when I execute the code it presents me an error called: " Runtime error '13' " But if I change #N/D to any other example text #N/A it accepts.

  • Old is not understand of vba anymore, calm hold on come help you the, pt.stackoverflow.com have many people who can do this.

1 answer

1


You can use the function Integrity()

Code

'percorre da linha 2 até a última preenchida em A
   For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    'se em B for #N/D
    If WorksheetFunction.IsNA(Cells(i, 2)) Then
    'apaga conteúdo de A
    Cells(i, 1).ClearContents
    End If
  'próxima linha
 Next i

Error

This error occurs because #N/D is not a String, but an error variable. Hence the function isNA() is used. However, #N/D can be searched with simple String search functions such as .Find

Another way

It is performed using the function Cverr()

'percorre da linha 2 até a última preenchida em A
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    'se em B houver erro
    If IsError(Cells(i, 2)) Then
        'Se em B for #N/D
        If Cells(i, 2) = CVErr(xlErrNA) Then
            'apaga conteúdo de A
            Cells(i, 1).ClearContents
        End If
    End If
    'próxima linha
Next i

Browser other questions tagged

You are not signed in. Login or sign up in order to post.