如果公式返回空白值,如何清除单元格? [英] How to clear cell if formula returns blank value?
本文介绍了如果公式返回空白值,如何清除单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的公式:
if(A1="","",1)
如果公式为"
,如何快速删除该公式?我尝试搜索空格,但是因为有一个公式,它不会返回空格.
How do I do a quick search to remove the formula if it is ""
?
I tried searching for blanks, but because there is a formula, it does not return a blank.
推荐答案
您需要使用以下代码
Sub ClearCell()
Dim Rng As Range
Set Rng = ActiveSheet.Range("A1")
Dim i As Long
For i = 1 To 10
If Rng.Cells(i,1) = "" Then
Rng.Cells(i,1).ClearContents
End If
Next i
End Sub
这将使单元格真正保持 Empty
的位置,而不包含零字符的"
字符串.
That will leave the cell truly EMPTY
and not with a zero-character ""
string.
如果您要清除单元格中任意长度的空格,请使用
If you are looking to clear arbitrary length whitespace in cells, use
If Len(Trim(Rng.Cells(i,1))) = 0 Then
' .....
对于任何数量的空格或没有空格(空字符串),此条件均成立.这样,几乎所有空白的东西都将被清除.
This condition will be true for any number of spaces or no spaces (empty string). That way (almost) anything which looks blank will get cleared.
这篇关于如果公式返回空白值,如何清除单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文