Type Mismatch Error 13 due to "#n/a" written as number in cells

radonwilson

New Member
Joined
Jun 23, 2021
Messages
49
Office Version
  1. 2019
Platform
  1. Windows
I have "#n/a" written in some of my cells(cells formatted as numbers) of column F, I am getting a type mismatch error 13. How to fix?

VBA Code:
Sub CheckErrors()

Dim r As Integer

For r = 1 To 10

If RS.Range("F" & r + 1).Value = "#n/a" Then

Debug.Print "Yes"

Else

Debug.Print "No"

End If

Next

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi radonwilson,

Try this (note I have added the cell address for easier referencing):

VBA Code:
Option Explicit
Sub CheckErrors()

    Dim r As Long
    Dim RS As Worksheet
    
    Set RS = ThisWorkbook.Sheets("Sheet1") '<-Sheet name to check. Change to suit if necessary.
    
    On Error Resume Next
        For r = 1 To 10
            If RS.Range("F" & r + 1).Value = CDbl(CVErr(xlErrNA)) Then
                Debug.Print RS.Range("F" & r + 1).Address & " - Yes"
            Else
                Debug.Print RS.Range("F" & r + 1).Address & " - No"
            End If
        Next r
    On Error GoTo 0

End Sub

Regards,

Robert
 
Upvote 0
VBA Code:
For r = 1 To 10
If RS.Range("F" & r + 1).Value = "#n/a" Then
Debug.Print "Yes"
Else
Debug.Print "No"
End If
Next
Try this instead of the above
VBA Code:
For r = 1 To 10
  If LCase(RS.Range("F" & r + 1).Text) = "#n/a" Then
    Debug.Print "Yes"
  Else
    Debug.Print "No"
  End If
Next
 
Upvote 0
Solution
Try this instead of the above
VBA Code:
For r = 1 To 10
  If LCase(RS.Range("F" & r + 1).Text) = "#n/a" Then
    Debug.Print "Yes"
  Else
    Debug.Print "No"
  End If
Next
Thanks Peter

May I have a little explanation on :-

1. the issue in my code.
2. how your code is working?
 
Upvote 0
1. the issue in my code.
The #n/a equates to an error in your code so the cell does not actually have a "value" it has an "error", hence the mismatch

2. how your code is working?
It uses the literal Text in the cell, not the "Value"
Rich (BB code):
If LCase(RS.Range("F" & r + 1).Text) = "#n/a" Then
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

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