Store #VALUE! #NUM! #REF! in variable.

Posted by Ommit on Stack Overflow See other posts from Stack Overflow or by Ommit
Published on 2010-05-05T16:10:45Z Indexed on 2010/05/05 18:18 UTC
Read the original article Hit count: 133

Filed under:
|
|
|

So a simple version of what I'm trying to do. Say I know there is an error in cell(1,1), furthermore I know it is either #num!, #ref! or #value!, I want to be able to store the respective error message in a variable, so I can print it to a different sheet. This is what I tried and it clearly failed.

Sub FindAndPrintErrors
dim Store as string
    If IsError(Range("A1"))) = True Then
        Store = Range("A1").value 'it breaks here'
    end if 
    range("B1") = Store
end sub

I know I can do this but I wonder if there is a better way.

Sub FindAndPrintErrors2
    dim Store
        If IsError(Range("A1"))) = True Then
            temp = Range("A1").value 'it breaks here'
        if temp = "error 2029" then
            store = "#num!"
        ' and so on'
        end if 
        range("B1") = Store
    end sub

© Stack Overflow or respective owner

Related posts about excel

Related posts about excel-vba