to detect error values in vba

abhaysanan

Board Regular
Joined
Jun 1, 2005
Messages
95
Hi,

i have this code in vba which checks through different cells and if it has an error, it moves to the next cell, or else, it puts some data in a database. The problem I am having is that on my sheet, I see 3 different error values as can be seen in the code. Somehow my code doesnt pick them up. Does any one know if there is an ISNA thing in vba??

Code:
 For j = 1 To 23
     
     For i = 1 To 24
     
       If (ActiveSheet.Range("Prices").Cells(i, j).Text <> "#N/A RI Tim") And _
       (ActiveSheet.Range("Prices").Cells(i, j).Text <> "#N/A Trd") And _
       (ActiveSheet.Range("Prices").Cells(i, j).Text <> "#N/A Sec") Then
        
        insBlpRoot = Trim(ActiveSheet.Range("Roots").Cells(i, j).Value)
        insAARoot = Trim(ActiveSheet.Range("AARoot").Cells(i, j).Value)
            
       'inserting into the database
        querystring = "INSERT INTO TradeSymb (" & _
            "BLPRoot, AARoot) " & _
            "VALUES ('" & insBlpRoot & "', '" & insAARoot & "')"
        
        Set qdInsertRoots = Conn.CreateQueryDef("", querystring)
        Set rsRoots = qdInsertRoots.OpenRecordset()
        
    Else
    
    End If
    
    Next i
    Next j
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Yes you can use IsNA() I think

If IsNA(x) Then
'......
End If

It seems that #N/A is not evaluated as text.

Hope this helps !

Ciao,

Don.
 
Upvote 0
Is "#N/A RI Tim" an Excel error, because it's new to me?

You can test for Excel's #N/A error like this:

Code:
If ActiveSheet.Range("Prices").Cells(i, j).Value <> CVErr(xlErrNA) Then
 
Upvote 0
i dont think its an excel error. its an error i get while tryin to get values from bloomberg!! i'll try out your solutions and c how it works. thanks for your help!
 
Upvote 0
HI,

none of the above solutions seem to work. I dont think its an excel error also. And when I put in the code which checks if its an excel error, it showed type mismatch... How do i fix it pls?
 
Upvote 0
Your if statement is using AND as a condition... which means all 3 error message need to exist... change it to OR
 
Upvote 0
But i'm making sure the value in my cell is NOT EQUAL to all the three errors...and thats y the usage of AND..I tried using IsNumeric and I think that works..i just check if value is numeric and if it is, i put in in database...
 
Upvote 0
Are the messages you are looking for text in the cells or message generated by Excel. If they are actual text, your compare (IF) will not work. Can you post a sample to the board?
 
Upvote 0
Instead of going to all the cells in the range and checking for errors why not use a "SpecialCells" loop that ONLY GOES TO CELLS WITH ERRORS ??

The following loop only goes to cells with errors within the designated range...

Code:
Public Sub OnlyErrCells()
'ONLY GOTO CELLS THAT HAVE AN ERROR IN RANGE A1:H26
  For Each CellErr In Range("A1:H26").SpecialCells(xlCellTypeFormulas, 16)
  
  MsgBox CellErr.Address
  
  Next CellErr
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,577
Members
449,039
Latest member
Arbind kumar

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