第一个代码:
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 :(得分:0)
尝试下面的代码(代码注释中的修改)
<!-- canvas(id="my_canvas" width="70" height="70") -->
<canvas id="my_canvas" width="70" height="70"></canvas>
<input type="hidden" id="myValue" value="10" />
<button id="btnUpdate">Update value by 10</button>
答案 1 :(得分:0)
试试这段代码。这将清除工作表中已使用范围的0,而不更改格式。
更新:
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Cells.Replace what:=0, Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next ws
答案 2 :(得分:0)
使用文件&gt;中的设置;选项&gt;高级并取消选中“Show zeros ...”设置。此设置基于每个工作表,因此,要将整个工作簿自动化,请将此代码放入ThisWorkbook模块
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
ActiveWindow.DisplayZeros = False
End Sub
现在零不会显示在任何工作表上。