简体   繁体   English

如果单元格的值为“”而不使用VBA,则清除单元格内容

[英]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! 谢谢你提出一个好问题!

  1. Select the entire column (but only one column at a time). 选择整个列(但一次只能选择一列)。
  2. Run Data ► Data Tools ► Text-to-Columns. 运行数据►数据工具►文本到列。
  3. Pick 🔘 Fixed width and click Finish . 选择🔘固定宽度,然后单击完成 No need to go through the other screens. 无需通过其他屏幕。
  4. All cells containing zero-length strings will become truly blank cells¹. 所有包含零长度字符串的单元格将成为真正的空白单元格¹。

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.

相关问题 VBA - 如果不包含值,如何跨多列清除单元格内容 - VBA - How to Clear Cell Contents across Multiple Columns if Value not Contained 根据其他单元格中的值清除单元格内容 - Clear contents of cell based on value in other cell VBA清除一定范围或单元格中的内容 - Vba clear contents of a certain range or cell 如果另一个单元格在 Vba 中更改,如何清除单元格的内容 - How To Clear Contents of A Cell If Another Cell Changes In Vba 在不使用宏或VBA的情况下获取作为活动单元格地址的单元格值 - Get the value of a cell that's the address of the active cell without using macros or VBA 宏以清除数据验证单元格的内容,如果特定的单元格公式更改了它的值 - Macro To Clear Contents of a Data Validation Cell IF Specific Cell Formula Changes it's Value 如果在vba中更改了单元格范围,则清除单元格内容 - Clear cell contents if another is changed for a range of cells in vba VBA 遍历所有工作表并清除单元格内容 - VBA to loop through all worksheets and clear cell contents 如果它们在数值范围内,如何清除VBA中的单元格内容 - How to clear cell contents in VBA if they are within a range of numeric values VBA单元格的设置值不会更改未保护工作表中的单元格内容 - VBA Setting value of cell does not change cell contents in unprotected sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM