簡體   English   中英

Excel VBA查找#N / A

[英]Excel VBA find #N/A

我有一個工作表,其中的公式在某些情況下會返回=NA() 使用VBA,我想找到#N / A,但是我無法調整此答案

lastrow = .Cells.Find(What:="*", _
                  After:=.Range("A1"), _
                  Lookat:=xlPart, _
                  LookIn:=xlFormulas, _
                  SearchOrder:=xlByRows, _
                  SearchDirection:=xlPrevious, _
                  MatchCase:=False).Row

我已經嘗試過What:=CVErr(xlErrNA)What:=xlErrNA以及What:="#N/A"無濟於事。

另一個困難是,我必須考慮荷蘭語,所以What:="#N/A"甚至在荷蘭語中也無法使用。

注意。 我出於好奇而問這個問題,因為我沒有在線找到方法。 目前,我正在計算哪些單元格包含=NA()

您正在查找單元格公式。 嘗試查看單元格 ,然后我可以使用字符串“#N / A”作為What參數來使它工作:

lastrow = .Cells.Find(What:="#N/A", _
            After:=.Range("A1"), _
            Lookat:=xlPart, _
            LookIn:=xlValues, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlPrevious, _
            MatchCase:=False).Row

請嘗試以下代碼,您應該使用循環讀取錯誤。

子測試()

If Range("A2").Text = "#N/A" Then
    MsgBox "hi"
End If

結束子

嗨,我有另一種解決方案,您已將這些公式值粘貼為文本和另一列

然后使用替換代碼,

請嘗試以下代碼。

Sub Tst()

    Columns("C:C").Select
    Selection.Copy
    Range("D1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

    Selection.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

End Sub

C列包含公式值(錯誤)。

這里的問題是,您正在尋找“#N / A”作為單元格的值,而不是該值,它是一個錯誤指示符,因此,如果您嘗試查找一個給您帶來錯誤的單元格,則必須使用這樣的東西:

If WorksheetFunction.IfError("Put here a loop to read the cells;"Error")="Error" then

"Write what you desire for cells with error"

end if

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM