简体   繁体   English

如何删除 excel 中的空单元格?

[英]How to remove empty cells in excel?

I want to remove the empty cells in excel of thousands of rows and columns can anyone help me on this?我想删除数千行和列的 excel 中的空单元格有人可以帮我吗? The values of the excel should be in order. excel的值应该是有序的。

Sample Input:样本输入:

在此处输入图像描述

Desired Output:所需的 Output:

在此处输入图像描述

Press Alt F11 to run a script as a macro.按 Alt F11 将脚本作为宏运行。 This website offers some insight that may be helpful.该网站提供了一些可能有用的见解。 https://www.excel-easy.com/vba/examples/delete-blank-cells.html https://www.excel-easy.com/vba/examples/delete-blank-cells.html

I hope this helps.我希望这有帮助。

This code is essentially the same as @Tony's, but it doesn't use any extra cells.此代码与@Tony 的代码基本相同,但它不使用任何额外的单元格。

Dim counter As Integer, i As Integer
counter = 1
For i = 1 To 10
    If Cells(i, 1) <> "" Then
        Cells(counter, 1) = Cells(i, 1)
        counter = counter + 1
    End If
Next i
For i = counter To 10
    Cells(i, 1) = ""
Next i

There is no chance of losing data, as there are blanks in the original, so that counter is always less than or equal to i .没有丢失数据的机会,因为原始文件中有空格,所以counter总是小于或等于i The last for..next loop clears any remaining visible previous data.最后一个for..next循环清除任何剩余的可见先前数据。

All you need to do is:您需要做的就是:

  • Select column A:B Select A:B 列
  • Go to ribbon > Start Go 到色带 >开始
  • Under editing > Search & Select编辑中 >搜索 & Select
  • Click > Select Special点击 > Select 特价
  • Click > Blanks单击 >空白

Now all your empty cells should be selected现在应该选择所有空单元格

  • Hit Ctrl - and shift cells up.点击Ctrl -并向上移动单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM