vba 删除 Excel 中具有零值的单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10411159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:00:06 来源:igfitidea点击:
Remove cells in Excel which have zero values
提问by sean
I have been trying to remove/hide cells which values are equal to zero (0).
我一直在尝试删除/隐藏值等于零 (0) 的单元格。
Sub HideRows()
Dim cell As Range, rng As Range
Cells.Rows.Hidden = False
On Error Resume Next
Set rng = Columns(5).SpecialCells(xlConstants, xlNumbers)
On Error GoTo 0
For Each cell In rng
If cell.Value = 0 Then
cell.EntireRow.Hidden = True
End If
Next
End Sub
The code removes the entire row. I want to remove the description of the value and the value.
该代码删除整行。我想删除值和值的描述。
回答by brettdj
This code will quickly clear (erase) values and comments from cells in column E that have a value of 0
此代码将快速清除(擦除)列 E 中值为 0 的单元格中的值和注释
Sub Testme()
Dim rng1 As Range
Set rng1 = Columns(5)
With rng1
.AutoFilter 1, "0"
With rng1.Offset
.ClearContents
.ClearComments
End With
With rng1.Offset(0, -1)
.ClearContents
.ClearComments
End With
End With
End Sub