How to fix #N/A error

fluffyvampirekitten

Board Regular
Joined
Jul 1, 2015
Messages
72
I'm trying to highlight the cell which display "#N/A"
However i only get errors at #N/A part .
Any ideas why?
Thanks in advance

Code:
Private Sub Simpat4_Missing_UserName_Dept()
' Update User Name and Dept from Missing User name & dept xlsx file
Dim MaxRowNum, RowNum As Long
'Step 29
    With Application
        .ScreenUpdating = False
        .Calculation = xlManual
        
    End With
    
    Sheets("Simpat").Select
    ' Find the max number of row
    MaxRowNum = 1
       
    Do While Cells(MaxRowNum, 2) <> "" Or Cells(MaxRowNum + 1, 2) <> ""
        MaxRowNum = MaxRowNum + 1
    Loop
    
    'Find the row with the USERNAME & DEPT - "NOT INDICATED" and use a vlookup Function
    RowNum = 1
    
    For RowNum = 1 To MaxRowNum
    
        If UCase(Cells(RowNum, 16)) Like "*NOT INDICATED*" Or UCase(Cells(RowNum, 17)) Like "*NOT INDICATED*" Then
        
            'Vlookup User Name from the file MISSINGUSERNAMEDEPT.xlsx
            Range("P" & RowNum).FormulaR1C1 = "= VLOOKUP(RC[-3],[MISSINGUSERNAMEDEPT.xlsx]Sheet1!R1:R1048576,2,0)"
                       
            
            'Vlookup Dept from the file MISSINGUSERNAMEDEPT.xlsx
            Range("Q" & RowNum).FormulaR1C1 = "= VLOOKUP(RC[-4],[MISSINGUSERNAMEDEPT.xlsx]Sheet1!R1:R1048576,3,0)"
      
            
            ' Fill only the "NOT INDICATED" Cells
            ' Don't use Autofill as it will overwrite every row
            Range(Cells(RowNum, "P"), Cells(RowNum, "Q")).Select
            Selection.Copy
            Selection.PasteSpecial Paste:=xlPasteValues
        End If
        
        
        [COLOR=#FF0000]If UCase(Cells(RowNum, 16).Value) Like "*#N/A*" Then
            Cells(RowNum, 16).Interior.Color = RGB(0, 0, 255)
        End If
        
        If UCase(Cells(RowNum, 17).Value) Like "*#N/A*" Then
            Cells(RowNum, 17).Interior.Color = RGB(0, 0, 255)
        End If[/COLOR]
        
        
        
    Next
    
               
    With Application
        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
        
    End With
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
you could just CF the sheet / columns to test for and display those errors
 
Upvote 0
.. or if you're set on using VBA, test:

Code:
WorksheetFunction.IsNA (Cells(RowNum, 16).Value)
'OR
Cells(RowNum, 16).Value = CVErr(xlErrNA)
 
Upvote 0

Forum statistics

Threads
1,217,366
Messages
6,136,128
Members
449,993
Latest member
Sphere2215

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