我剛剛在我的部門發佈了一個Excel加載項,我一直在爲最近2個月的時間內檢查大約30個驗證錯誤。我在所有情況下都處理錯誤陷阱(因爲它現在正在出現),但是今天我收到了一個可怕的喚醒電話,因爲我收到了兩個重要錯誤的自動電子郵件(我構建在錯誤處理中的一個功能)。我已經發布了關於第一個錯誤here的問題,並認爲我會爲第二個錯誤開始一個新問題,因爲它與第一個錯誤無關。#REF!粘貼爲值,但循環時沒有看到這樣
我的代碼如下
Private Sub symbolCheck()
On Error GoTo ErrHandler
Application.StatusBar = "(3/16) Checking for invalid symbols"
Dim MyArray As Variant
Dim replacementsMade As Boolean
replacementsMade = False
MyArray = ActiveSheet.UsedRange
For i = LBound(MyArray) To UBound(MyArray)
For j = LBound(MyArray, 2) To UBound(MyArray, 2)
If MyArray(i, j) <> "" Then
'Apostrophe/Closing Single Quote
If InStr(1, MyArray(i, j), "’") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "’", Chr(39))
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Apostrophe
If InStr(1, MyArray(i, j), "`") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "`", Chr(39))
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Opening Single Quote
If InStr(1, MyArray(i, j), "‘") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "‘", Chr(39))
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Double Open Quotes
If InStr(1, MyArray(i, j), "「") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "「", """")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Double Closing Quotes
If InStr(1, MyArray(i, j), "」") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "」", """")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Dash
If InStr(1, MyArray(i, j), "–") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "–", "-")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Registered Trademark (R)
If InStr(1, MyArray(i, j), "®") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "®", "(R)")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Trademark (TM)
If InStr(1, MyArray(i, j), "™") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "™", "(TM)")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Degree Symbol
If InStr(1, MyArray(i, j), "°") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "°", " degrees")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Multiplication/x Symbol
If InStr(1, MyArray(i, j), "×") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "×", "x")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Upside-Down Question Mark Symbol
If InStr(1, MyArray(i, j), "¿") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "¿", "")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Solid Bullet Symbol
If InStr(1, MyArray(i, j), "•") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "•", "")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Triple Dots Symbol
If InStr(1, MyArray(i, j), "…") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "…", "...")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Euro Symbol
If InStr(1, MyArray(i, j), "€") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "€", "")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Linebreak Symbol
If InStr(1, MyArray(i, j), "|") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "|", ",")
If replacementsMade = False Then
replacementsMade = True
End If
End If
' 'Less Than Symbol
' If InStr(1, MyArray(i, j), "<") > 0 Then
' MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "<", "<")
' End If
' 'Greater Than Symbol
' If InStr(1, MyArray(i, j), ">") > 0 Then
' MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), ">", ">")
' End If
'Half Fraction
If InStr(1, MyArray(i, j), "½") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "½", " 1/2")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'Three Quarter Fraction
If InStr(1, MyArray(i, j), "¾") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "¾", " 3/4")
If replacementsMade = False Then
replacementsMade = True
End If
End If
'One Quarter Fraction
If InStr(1, MyArray(i, j), "¼") > 0 Then
MyArray(i, j) = WorksheetFunction.Substitute(MyArray(i, j), "¼", " 1/4")
If replacementsMade = False Then
replacementsMade = True
End If
End If
End If
Next j
Next i
If replacementsMade Then
ActiveSheet.UsedRange = MyArray
End If
Set MyArray = Nothing
Exit Sub
ErrHandler:
Err.Raise Err.Number, "symbolCheck", Err.Description
End Sub
上線發生這種錯誤
If MyArray(i, j) <> "" Then
當我 = 209和Ĵ = 60,所以我做了一些戳看去在數組中查看該位置的值。當我查看數組插槽的監視列表值時,該值僅表示Error 2023
。所以,我看着與那些我和j對應的單元格的值和唉,我終於明白了爲什麼錯誤被提出。單元格中的值最初是一個帶有引用錯誤的公式,並且因爲我在運行此子文件之前將其複製/粘貼爲值,所以我認爲我會很好。我不知道#REF!
沒有被視爲明文?
這使我對我的問題
我如何處理這種情況?更確切地說,如果#REF!
即使在作爲值的複製/粘貼之後仍未被視爲明文,我如何能夠在電子表格中刪除#REF!
值(不使用「查找/替換」)?
''#REF <> 「」,所以它出現在你的if語句是工作的罰款? – findwindow
不,該行是當被檢查的值是'#REF'時發生錯誤的地方。它應該通過if語句中的代碼,如果它被視爲文本,就像其他所有內容一樣。 – CaffeinatedCoder