[英]Clear cell contents if cell's value is “” without using VBA
I've a column A with 'empty cell' or 'number stored as text'. 我有一个带有“空单元格”或“存储为文本的数字”的列A. I need to get 'empty cell' or 'numbers values' to create a graph.
我需要获得“空单元格”或“数字值”来创建图形。
What I usually do is a create a second column using =IF(A1<>"";cnum(A1);"")
. 我通常做的是使用
=IF(A1<>"";cnum(A1);"")
创建第二列=IF(A1<>"";cnum(A1);"")
。 But the graph displays "" as 0 so I need to get rid of the "" values. 但图表显示“”为0,所以我需要摆脱“”值。 Copy then Pastevalues in Excel doesn't do the job.
然后在Excel中复制粘贴值不起作用。
I often recreate on the fly a small VBA code to do that ( For each cell in Range() IF cell.value ="" THEN cell.ClearContents...
). 我经常在运行中重新创建一个小的VBA代码(
For each cell in Range() IF cell.value ="" THEN cell.ClearContents...
)。 That works great... but using VBA seems like an overkill. 这很有效......但使用VBA看起来有点过分。
Sometimes, I'll just copy the range, paste it in a text editor, copy it and paste if back in Excel. 有时,我只是复制范围,将其粘贴到文本编辑器中,复制并粘贴到Excel中。 That works great too... but I'm not very pleased by that technique either.
这也很有效......但我对这种技术也不是很满意。
How would you do that in Excel without using VBA ? 如果不使用VBA,您将如何在Excel中执行此操作?
Edit 1 : I forgot to mention I would also often use =IF(A1<>"";cnum(A1);"X")
then Copy/PasteValues then Ctrl+F for "X" and replace it with nothing. 编辑1 :我忘了提到我也常常使用
=IF(A1<>"";cnum(A1);"X")
然后使用Copy / PasteValues然后按Ctrl + F代替“X”并将其替换为空。 (If there are text values, I'll put "XYXYX" instead to be sure) (如果有文本值,我会把“XYXYX”改为确定)
Edit 2 : I should have mentionned I'm only looking for solutions which either are either 1 second quicker (which means no or little use of the mouse), or as quick but nicer ! 编辑2 :我应该提到我只是寻找能够快1秒(这意味着没有或很少使用鼠标)的解决方案,或者快速但更好!
Assuming your values come in "A" Column, put following formula to the "B" column: 假设您的值位于“A”列中,请将以下公式放入“B”列:
=IF(A1<>"", 1, "")
Then copy whole "A" Column and Paste Special over the "B" Column specifying "Values" and then "Multiply" as operation and check "Skip Blanks" 然后将整个“A”列和Paste Special复制到指定“Values”的“B”列上,然后将“Multiply”复制为操作并选中“Skip Blanks”
After that copy whole "B" Column and Paste Special it over the "C" column (assuming it is empty) specifying "Values" and then "Add" as operation and also check "Skip Blanks". 之后复制整个“B”列并将其粘贴到“C”列(假设它为空),指定“值”,然后“添加”作为操作,并检查“跳过空白”。
So you have numeric data in "C" column with properly empty cells where you have no values. 因此,您在“C”列中有数字数据,其中没有值的正确空单元格。
Thanks for a good question! 谢谢你提出一个好问题!
This procedure can quickly convert text-that-look-like-numbers to true numbers as well. 此过程可以快速将类似文本的数字转换为真实数字。
The VBA equivalent can greatly speed up looping through every cell in a range and dealing with them individually. 等效的VBA可以极大地加速循环范围内的每个单元并单独处理它们。
Dim c As Long
With Range("A1").CurrentRegion `<~~ set to the desired range of one or more columns
For c = 1 To .Columns.Count
.Columns(c).TextToColumns Destination:=.Columns(c), _
DataType:=xlFixedWidth, FieldInfo:=Array(0, 1)
Next c
End With
¹ This procedure is not applicable to cells with formulas returning zero-length strings. ¹ 此过程不适用于具有返回零长度字符串的公式的单元格。 Those must be converted to their returned values with Copy, Paste Special, Values before running through Text-to-Columns.
在运行Text-to-Columns之前,必须使用Copy,Paste Special,Values将它们转换为返回值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.