Excel精英培训网

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

[已解决]求版主及各高手赐一段代码,谢谢,指导一下新人

[复制链接]
发表于 2012-10-29 12:03 | 显示全部楼层 |阅读模式
5学分
如附件,
1.在C列中查找关键字“Mixing  tower  U"所在行,删除此行(不包括此行)上面直到第二行的所有行(C1所在行保留)。
2.在C列中查找关键字“filler supply 05"所在行,删除此行(包括此行)向下所有行
最佳答案
2012-10-29 12:36
本帖最后由 hwc2ycy 于 2012-10-29 12:38 编辑
  1. Sub FindDelete()
  2.     '没有做大小写匹配
  3.     Dim s1 As String, s2 As String
  4.     Dim rg As Range
  5.     Dim iRow As Long
  6.     On Error Resume Next
  7.     '关闭刷屏
  8.     Application.ScreenUpdating = False
  9.     s1 = "Mixing tower U"
  10.     s2 = "filler supply 05"
  11.     Set rg = Range("c:c").Find(s1)
  12.     If (Not rg Is Nothing) Then
  13.         If rg.Row <> 2 Then Range("c2:c" & rg.Row - 1).EntireRow.Delete
  14.     End If
  15.     Set rg = Nothing
  16.     iRow = Range("a1").End(xlDown).Row
  17.     Set rg = Range("c:c").Find(s2)
  18.     If (Not rg Is Nothing) Then
  19.         If rg.Row <> iRow Then Range("c" & rg.Row + 1 & ":c" & iRow).EntireRow.Delete
  20.     End If
  21. End Sub
复制代码
重新改了下,之前逻辑关系不够严谨。

69978.zip

239.85 KB, 下载次数: 18

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-10-29 12:28 | 显示全部楼层
本帖最后由 hwc2ycy 于 2012-10-29 12:36 编辑
  1. Sub FindDelete()
  2.     '没有做大小写匹配
  3.     Dim s1 As String, s2 As String
  4.     Dim rg As Range
  5.     Dim iRow As Long
  6.     On Error Resume Next
  7.     '关闭刷屏
  8.     Application.ScreenUpdating = False
  9.     s1 = "Mixing tower U"
  10.     s2 = "filler supply 05"
  11.     Set rg = Range("c:c").Find(s1)
  12.     If (Not rg Is Nothing) And rg.Row <> 2 Then Range("c2:c" & rg.Row - 1).EntireRow.Delete
  13.     iRow = Range("a1").End(xlDown).Row

  14.    Set rg = Range("c:c").Find(s2)
  15.     If (Not rg Is Nothing) And rg.Row <> iRow Then Range("c" & rg.Row + 1 & ":c" & iRow).EntireRow.Delete
  16. End Sub
复制代码
第2个关键字C列木有啊。
回复

使用道具 举报

发表于 2012-10-29 12:36 | 显示全部楼层    本楼为最佳答案   
本帖最后由 hwc2ycy 于 2012-10-29 12:38 编辑
  1. Sub FindDelete()
  2.     '没有做大小写匹配
  3.     Dim s1 As String, s2 As String
  4.     Dim rg As Range
  5.     Dim iRow As Long
  6.     On Error Resume Next
  7.     '关闭刷屏
  8.     Application.ScreenUpdating = False
  9.     s1 = "Mixing tower U"
  10.     s2 = "filler supply 05"
  11.     Set rg = Range("c:c").Find(s1)
  12.     If (Not rg Is Nothing) Then
  13.         If rg.Row <> 2 Then Range("c2:c" & rg.Row - 1).EntireRow.Delete
  14.     End If
  15.     Set rg = Nothing
  16.     iRow = Range("a1").End(xlDown).Row
  17.     Set rg = Range("c:c").Find(s2)
  18.     If (Not rg Is Nothing) Then
  19.         If rg.Row <> iRow Then Range("c" & rg.Row + 1 & ":c" & iRow).EntireRow.Delete
  20.     End If
  21. End Sub
复制代码
重新改了下,之前逻辑关系不够严谨。

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-24 23:45 , Processed in 0.313997 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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