Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2265|回复: 3

[已解决]求助:错误“1004”:应用程序定义或对象定义错误

[复制链接]
发表于 2012-5-2 18:24 | 显示全部楼层 |阅读模式
代码的目的是判断每行第11列的数值,如果小于0则删除整行(不光是清空这行数据)
自己写的代码运行时出现错误“1004”:应用程序定义或对象定义错误
请帮忙看一下哪里出错了
万分感谢!

  1. Private Sub DeleteLine()
  2.         Dim i As Integer
  3.                 For i = 1 To Sheet3.Cells(Rows.Count, 11).End(xlUp).Row
  4.                         If Cells(i, 11) < 0 Then
  5.                                 Rows("i").Select
  6.                                 Selection.Delete Shift:=xlUp
  7.                                 i = i - 1
  8.                         End If
  9.                 Next i
  10. End Sub
复制代码


最佳答案
2012-5-2 18:28
Private Sub DeleteLine()

       Dim i As Integer
                For i = 1 To Sheet3.Cells(Rows.Count, 11).End(xlUp).Row

                        If Cells(i, 11) < 0 Then

                                Rows(i).Select

                               Selection.Delete Shift:=xlUp

                               i = i - 1

                       End If

               Next i
End Sub
发表于 2012-5-2 18:28 | 显示全部楼层    本楼为最佳答案   
Private Sub DeleteLine()

       Dim i As Integer
                For i = 1 To Sheet3.Cells(Rows.Count, 11).End(xlUp).Row

                        If Cells(i, 11) < 0 Then

                                Rows(i).Select

                               Selection.Delete Shift:=xlUp

                               i = i - 1

                       End If

               Next i
End Sub
回复

使用道具 举报

发表于 2012-5-2 19:53 | 显示全部楼层
  1. Private Sub DeleteLine()
  2.     Dim i As Integer
  3.     For i = Cells(Rows.Count, 11).End(xlUp).Row To 1 Step -1
  4.         If Cells(i, 11) < 0 Then
  5.             Rows(i).Delete
  6.         End If
  7.     Next i
  8. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2012-5-3 08:56 | 显示全部楼层
lisachen 发表于 2012-5-2 18:28
Private Sub DeleteLine()

       Dim i As Integer

解决了,非常感谢!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-3-28 17:45 , Processed in 0.270840 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表