Shop #CURRENCY! #NUM! #REF! in variable

So, a simple version of what I'm trying to do. Let's say I know that there is an error (1,1) in the cell, in addition, I know that this is either #num !, #ref! or #value !, I want to be able to save the corresponding error message in a variable, so I can print it on another sheet. This is what I tried, and it clearly didn't work out.

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
+3
source share
2 answers

Instead of .value try .Text. This can be stored in your variable.

?cells(1,2).text
#N/A
?cells(1,2).value
Error 2042
?cells(2,2).text
#REF!
?cells(2,2).value
Error 2023
+4
source

Variant. , , .

, :

Public Sub copyFromCellIfError()
    Dim v
    v = [q42]

    If IsError(v) Then
        [z99] = v
    End If
End Sub

, , .

+1

Source: https://habr.com/ru/post/1744196/


All Articles