Delete
删除单元格。在删除单元格时,可以设置单元格的移动方向(在删除某个单元格后,旁边的单元格会根据设置的单元格移动方向填补空缺)。如:
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\Report.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.Range("A10")'以这个指定的单元格为基准
Rg.Delete(MSExcel.XlDirection.xlUp) '下面的单元格上移
App.Visible = True
利用Delete方法,同时结合EntireRow和EntireColumn属性,可删除整行和整列。如:
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\Report.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.Range("A10")'以这个指定的单元格为基准
Rg.EntireColumn.Delete(MSExcel.XlDirection.xlToLeft) '右面的单元格左移
App.Visible = True
在删除多行或多列时,一样可以设置单元格的移动方向。如:
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\Report.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.Rows("1:3")'选定多行
Rg.Delete(MSExcel.XlDirection.xlUp) '下面的单元格上移
Rg = Ws.Columns("D:F") '选定多列
Rg.Delete(MSExcel.XlDirection.xlToLeft) '右面的单元格左移
App.Visible = True
http://www.foxtable.com/webhelp/scr/2121.htm