Excel精英培训网

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

[已解决]删除整行

[复制链接]
发表于 2014-4-13 19:20 | 显示全部楼层 |阅读模式
请编写代码:
  第1与2行为一组、3与4、5与6、7与8分别为一组,以此类推分组,如果每组两行数字个数同时小于5时,就删除这两整行。
  如表1中11与12、表2中5与6两行数字都小于5个,就删除这4整行.删除后的表如下:
谢谢!
最佳答案
2014-4-13 20:13
Sub Macro1()
Dim i&, rng As Range, x%, y%
For i = 1 To Range("a65536").End(xlUp).Row - 1 Step 2
    x = Application.CountA(Cells(i, 1).Resize(1, 7))
    y = Application.CountA(Cells(i + 1, 1).Resize(1, 7))
    If x < 5 And y < 5 Then
        If rng Is Nothing Then
            Set rng = Cells(i, 1).Resize(2, 7)
        Else
            Set rng = Union(rng, Cells(i, 1).Resize(1, 7))
        End If
    End If
Next
If Not rng Is Nothing Then rng.EntireRow.Delete
End Sub

删除整行.rar

18.6 KB, 下载次数: 4

发表于 2014-4-13 19:49 | 显示全部楼层
  1. Sub Macro1()
  2. Dim i&, rng As Range, x%, y%
  3. For i = 1 To 11 Step 2
  4.     x = Application.CountA(Cells(i, 1).Resize(1, 7))
  5.     y = Application.CountA(Cells(i + 1, 1).Resize(1, 7))
  6.     If x < 5 And y < 5 Then
  7.         If rng Is Nothing Then
  8.             Set rng = Cells(i, 1).Resize(2, 7)
  9.         Else
  10.             Set rng = Union(rng, Cells(i, 1).Resize(1, 7))
  11.         End If
  12.     End If
  13. Next
  14. If Not rng Is Nothing Then rng.Delete shift:=xlUp
  15. End Sub
复制代码
回复

使用道具 举报

发表于 2014-4-13 19:52 | 显示全部楼层
………………

删除整行.zip

10.95 KB, 下载次数: 7

回复

使用道具 举报

 楼主| 发表于 2014-4-13 20:08 | 显示全部楼层
dsmch 发表于 2014-4-13 19:49

请把工作表整行删除
谢谢!
回复

使用道具 举报

发表于 2014-4-13 20:13 | 显示全部楼层    本楼为最佳答案   
Sub Macro1()
Dim i&, rng As Range, x%, y%
For i = 1 To Range("a65536").End(xlUp).Row - 1 Step 2
    x = Application.CountA(Cells(i, 1).Resize(1, 7))
    y = Application.CountA(Cells(i + 1, 1).Resize(1, 7))
    If x < 5 And y < 5 Then
        If rng Is Nothing Then
            Set rng = Cells(i, 1).Resize(2, 7)
        Else
            Set rng = Union(rng, Cells(i, 1).Resize(1, 7))
        End If
    End If
Next
If Not rng Is Nothing Then rng.EntireRow.Delete
End Sub
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-23 19:08 , Processed in 0.348579 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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