我尝试使用以下代码删除空行:
worksheet.Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
上面的代码工作正常,但给出运行时错误“1004”:未找到单元格。
最佳答案
On Error Resume Next
worksheet.Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
当没有空白单元格时,错误处理会有所帮助。如果没有这样的单元格,SpecialCells(xlCellTypeBlanks)
将始终返回错误,因此如果您想使用 SpecialCells( xlCellTypeBlanks)
.
关于excel - 使用VBA删除Excel中的空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7876340/