
CAD VBA删除excel行的问题
Setxlapp=CreateObject("excel.application")Setxlbook=xlapp.workbooks.Open("C:\Users\Ad...
Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.workbooks.Open("C:\Users\Administrator\Desktop\test\结算.xlsx") '打开的EXCEL路径
Set xlsheet = xlbook.worksheets("表三") '打开EXCEL中的工作表
excelSheet.Rows(10).Delete
excelSheet.Rows(11).Delete
excelSheet.Rows(12).Delete
excelSheet.Rows(13).Delete
excelSheet.Rows(14).Delete
excelSheet.Rows(15).Delete
excelSheet.Rows(16).Delete
excelSheet.Rows(17).Delete
excelSheet.Rows(18).Delete
excelSheet.Rows(19).Delete
excelSheet.Rows(20).Delete
这样一段代码,运行后实际只删除了5行,是什么问题?求解 展开
Set xlbook = xlapp.workbooks.Open("C:\Users\Administrator\Desktop\test\结算.xlsx") '打开的EXCEL路径
Set xlsheet = xlbook.worksheets("表三") '打开EXCEL中的工作表
excelSheet.Rows(10).Delete
excelSheet.Rows(11).Delete
excelSheet.Rows(12).Delete
excelSheet.Rows(13).Delete
excelSheet.Rows(14).Delete
excelSheet.Rows(15).Delete
excelSheet.Rows(16).Delete
excelSheet.Rows(17).Delete
excelSheet.Rows(18).Delete
excelSheet.Rows(19).Delete
excelSheet.Rows(20).Delete
这样一段代码,运行后实际只删除了5行,是什么问题?求解 展开
展开全部
把
excelSheet.Rows(10).Delete
excelSheet.Rows(11).Delete
excelSheet.Rows(12).Delete
excelSheet.Rows(13).Delete
excelSheet.Rows(14).Delete
excelSheet.Rows(15).Delete
excelSheet.Rows(16).Delete
excelSheet.Rows(17).Delete
excelSheet.Rows(18).Delete
excelSheet.Rows(19).Delete
excelSheet.Rows(20).Delete
改成:
Rows("10:20").Delete
原因:
删除第10行后原来的第11行就成了第10行,并不是原来的第11行,所以你的代码会删除10、12、14、16、18、20、22、24行
有什么不懂得欢迎继续追问,满意请及时采纳。
excelSheet.Rows(10).Delete
excelSheet.Rows(11).Delete
excelSheet.Rows(12).Delete
excelSheet.Rows(13).Delete
excelSheet.Rows(14).Delete
excelSheet.Rows(15).Delete
excelSheet.Rows(16).Delete
excelSheet.Rows(17).Delete
excelSheet.Rows(18).Delete
excelSheet.Rows(19).Delete
excelSheet.Rows(20).Delete
改成:
Rows("10:20").Delete
原因:
删除第10行后原来的第11行就成了第10行,并不是原来的第11行,所以你的代码会删除10、12、14、16、18、20、22、24行
有什么不懂得欢迎继续追问,满意请及时采纳。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询