你可以簡單地使用興田工作表函數來計算錯誤#:
LReturnValue = Application.Worksheetfunction.CountIf(Range("A:A"),IsError) > 0
我想這應該做到這一點,並會通知你有多少錯誤,在你選擇的範圍內被發現。
REVISED
Sub CheckRangeForErrors()
Dim errCount As Long
Dim rng As Range
Dim cl As Range
Dim col As String
col = Application.InputBox("Enter the column letter you would like to check for errors", "Column Name?")
If Not Len(col) = 1 Then
MsgBox "You have entered an invalid selection", vbCritical
Exit Sub
End If
Set rng = Sheets("Lookup Addition").Range(col & "1", Range(col & "1048576").End(xlUp))
errCount = Application.Evaluate("COUNTIF("& rng.Address &",IsError)")
If errCount = 0 Then
MsgBox "there were no errors", vbOKOnly
Else
MsgBox "there were " & errCount & " errors", vbOKOnly
End If
End Sub
這取決於你想要做什麼。如果在該範圍內有任何**錯誤值,您是否想簡單地返回「True」?無論如何,你將不得不遍歷整個範圍。我會發佈一個答案。 – 2013-04-25 15:07:40