Excel精英培训网

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

[已解决]删除合计与小计行

[复制链接]
发表于 2014-12-28 23:06 | 显示全部楼层 |阅读模式
求助.zip (15.38 KB, 下载次数: 14)
发表于 2014-12-28 23:25 | 显示全部楼层
改自示例代码:
Sub 宏1()
With Worksheets(2).UsedRange
    Set c = .Find("合计", LookIn:=xlValues)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
           If InStr(s, "," & c.Row & ":") < 1 Then s = s & "," & c.Row & ":" & c.Row
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
    firstAddress = ""
    Set c = .Find("小计", LookIn:=xlValues)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
           If InStr(s, "," & c.Row & ":") < 1 Then s = s & "," & c.Row & ":" & c.Row
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With
If Len(s) Then Range(Mid(s, 2)).Delete
End Sub

点评

find方法适用少量的数据,数据多时反不如循环了  发表于 2014-12-29 06:06
回复

使用道具 举报

 楼主| 发表于 2014-12-28 23:33 | 显示全部楼层
djyjysxxs 发表于 2014-12-28 23:25
改自示例代码:
Sub 宏1()
With Worksheets(2).UsedRange

试一试先
回复

使用道具 举报

发表于 2014-12-28 23:36 | 显示全部楼层
把With Worksheets(2).UsedRange中的2改成具体名字吧。
做的时候是复制了一张表,所以是2。发上来时忘改过来了。
回复

使用道具 举报

发表于 2014-12-29 06:05 | 显示全部楼层    本楼为最佳答案   
  1. Sub Macro1()
  2. On Error Resume Next
  3. Application.ScreenUpdating = False
  4. w = Array("小计", "合计")
  5. With ActiveSheet.UsedRange
  6.     For i = 0 To UBound(w)
  7.         .Replace w(i), "=" & w(i)
  8.         .SpecialCells(xlCellTypeFormulas, 23).EntireRow.Delete
  9.     Next
  10. End With
  11. Application.ScreenUpdating = True
  12. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2014-12-29 08:41 | 显示全部楼层
dsmch 发表于 2014-12-29 06:05

都能达到目的,5楼0.64秒,2楼的3.7秒,谢谢
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 08:13 , Processed in 0.419325 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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