使用VBA删除Excel中的空行 [英] Deleting Empty rows in Excel using VBA

查看:687
本文介绍了使用VBA删除Excel中的空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下代码删除空行:

I am trying to delete Empty rows by using below code:

worksheet.Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

上面的代码工作正常,但给出运行时错误'1004':没有找到单元格。

The code above is working fine, but giving run time error '1004': No Cells were found.

推荐答案

On Error Resume Next
worksheet.Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0

当没有空白单元格时,错误处理有帮助。 SpecialCells(xlCellTypeBlanks)将永远返回一个错误,如果没有像这样的单元格,那么错误处理是唯一的方式(我知道)处理它,如果你想使用 SpecialCells(xlCellTypeBlanks)

The error handling helps when there are no blank cells. SpecialCells(xlCellTypeBlanks) will always return an error if there are no cells like that so error handling is the only way (that I know of) to deal with it if you want to use SpecialCells(xlCellTypeBlanks).

这篇关于使用VBA删除Excel中的空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆