我有兩個vba代碼,我想合併爲單個進程。請需要某人幫忙。清零零公式和非公式單元格
第一代碼:
Sub DelAllZeros()
Application.Calculation = xlCalculationManual
Dim ws As Worksheet
For Each ws In Worksheets
On Error Resume Next
Set frange = ws.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0
If Not frange Is Nothing Then
For Each c In frange
If c.Value = 0 Then
c.Formula = ClearContents
End If
Next c
End If
Set frange = Nothing
Next ws
End Sub
第二代碼:
Sub DelAllZeros1()
Dim ws As Worksheet
For Each ws In Worksheets
On Error Resume Next
ws.Select
Cells.Replace What:="0", Replacement:="", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Next ws
End Sub
第一代碼將從式細胞和秒代碼清除 「0」 將清除非公式的單元格。
所以你想要清除所有細胞(公式或非公式)「0」?你的源範圍是什麼,整個工作表? –
我想清除整個工作簿中的所有零值。如果任何單元格包含零(公式或非公式),應該清除(如空白) –
好的,請嘗試在我的答案下面的代碼,讓我知道它是否適合你 –