删除空单元格(向上移动)

我的代码下面怎么了? 我想删除空单元格,并将其余的数据(大约10列)

但是我得到错误:应用程序定义或对象定义的错误。

Sub delete_empty_cells() Sheets("Incidents_data").Select Cells.Select Selection.SpecialCells(xlCellTypeBlanks).Select Selection.Delete Shift:=xlUp End Sub 

将您的单元格删除限制为Worksheet.UsedRange属性 。

 With Worksheets("Incidents_data") .UsedRange.Cells.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp End With