Excel IFERROR修改所有錯誤公式 VBA實戰 - 會計

Table of Contents

用途:將所有無效公式以IFERROR公式處理為空白字串

下載(xlam):https://reurl.cc/7neNy
Demo:https://i.imgur.com/Oz6MOL5.gif
Demo下載(xlsm):https://reurl.cc/ApKaj
xlam增益集使用方法:https://i.imgur.com/1KvzYVc.gif

==

記得以前在某所案件歸檔前的File Check

會檢查Excel檔案所有的無效公式(#DIV/0!, #NAME?, #N/A)

這些無效公式一兩個手動處理還好,但常常莫名就有上百個要處理,

這時慢慢一個一個處理就滿浪費時間的,

這個小VBA會檢查所有工作表的公式,如果是錯誤的公式的話,會用IFERROR把它包起來

原始碼如下,會開啟VBE(ALT+F11)的話可以直接複製貼上,再按F5執行即可:

Sub Replace_Formula_by_Adding_IFERROR()

Dim Sh As Worksheet
Dim cell As Range
Dim FormulaRng As Range

On Error Resume Next
For Each Sh In Worksheets
Set FormulaRng = Sh.Cells.SpecialCells(xlCellTypeFormulas)
If Not FormulaRng Is Nothing Then
For Each cell In FormulaRng
If IsError(cell) Then
cell.Formula = "=iferror(" & Mid(cell.Formula, 2) & ", """")"
End If
Next cell
End If
Next Sh
On Error GoTo 0

End Sub

--
Accoding: https://www.facebook.com/AccodingTW/

--

All Comments

Rosalind avatarRosalind2019-05-10
謝謝分享,超實用的
Zanna avatarZanna2019-05-12
剛歸完檔路過
Edith avatarEdith2019-05-14