简体   繁体   English

如果在列范围内所有单元格都为空白,则在Excel中删除一行

[英]Delete a row in excel if all cells are blank in a range of columns

I have been looking around for an answer to this question for awhile now. 我一直在寻找这个问题的答案已有一段时间了。 I've found multiple great resources that show how to use a macro to delete a row if a cell within a specified column is blank but I haven't been able to find anything that will allow you to check a range of columns and delete a row if all cells in that range of columns is empty (if D1:F1 is entirely blank then delete row 1 but if in the range D2:F2 E2 has data in it don't delete that row). 我发现了许多很棒的资源,它们显示了如果指定列中的单元格为空时如何使用宏删除行,但是我找不到任何可以检查列范围并删除列的内容。如果该列范围内的所有单元格为空,则返回行(如果D1:F1完全为空,则删除第1行,但如果D2:F2范围内的E2中有数据,则不要删除该行)。

Here's the code that I've been trying to mess around with 这是我一直试图弄乱的代码

Application.ScreenUpdating = False
Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Application.ScreenUpdating = True

I found the above code from this answer Excel VBA: Delete entire row if cell in column A is blank (Long Dataset) 我从此答案Excel VBA中找到了上面的代码:如果A列中的单元格为空,则删除整行(长数据集)

If I try and modify that code to say 如果我尝试修改该代码以说

Columns("D:F").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

I then get an error message which says "Run-time error 1004: Cannot use that command on overlapping sections." 然后,我收到一条错误消息,内容为“运行时错误1004:无法在重叠的部分上使用该命令”。

您必须做一个气泡来遍历各列,因为如果同一行中有不止一个单元格中有空白单元格,则该气泡将不起作用。

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

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