Excel精英培训网

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

[已解决]删除特定数据

[复制链接]
发表于 2016-5-20 10:09 | 显示全部楼层 |阅读模式
本帖最后由 乐乐2006201506 于 2016-5-20 16:42 编辑

        将附件工作簿中工作表3中的姓名,在工作表1中找到并达到工作表2中的效果。如果找不到的姓名,用红色在工作表3中相应的单元格中标注。谢谢!
最佳答案
2016-5-20 11:06
  1. Sub Macro1()
  2. Dim arr, brr, d, d2, i&
  3. Set d = CreateObject("scripting.dictionary")
  4. Set d2 = CreateObject("scripting.dictionary")
  5. Sheet1.Activate
  6. arr = Range("a6").CurrentRegion
  7. brr = Sheet3.Range("a1").CurrentRegion
  8. For i = 1 To UBound(arr)
  9.     d2(arr(i, 2)) = ""
  10. Next
  11. For i = 1 To UBound(brr)
  12.     If Not d2.exists(brr(i, 1)) Then Sheet3.Cells(i, 1).Interior.ColorIndex = 3
  13.     d(brr(i, 1)) = ""
  14. Next
  15. For i = 1 To UBound(arr)
  16.     If d.exists(arr(i, 2)) Then
  17.         n = Range("a65536").End(xlUp).Row
  18.         If Cells(n, 1) = arr(i, 1) - 1 Then n = n + 1 Else n = n + 2
  19.         Cells(i + 5, 1).Resize(1, 2).Cut Cells(n, 1)
  20.     End If
  21. Next
  22. Range("a6").Resize(UBound(arr), 2).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  23. End Sub
复制代码

删除特定人员姓名.rar

22.59 KB, 下载次数: 4

发表于 2016-5-20 11:06 | 显示全部楼层    本楼为最佳答案   
  1. Sub Macro1()
  2. Dim arr, brr, d, d2, i&
  3. Set d = CreateObject("scripting.dictionary")
  4. Set d2 = CreateObject("scripting.dictionary")
  5. Sheet1.Activate
  6. arr = Range("a6").CurrentRegion
  7. brr = Sheet3.Range("a1").CurrentRegion
  8. For i = 1 To UBound(arr)
  9.     d2(arr(i, 2)) = ""
  10. Next
  11. For i = 1 To UBound(brr)
  12.     If Not d2.exists(brr(i, 1)) Then Sheet3.Cells(i, 1).Interior.ColorIndex = 3
  13.     d(brr(i, 1)) = ""
  14. Next
  15. For i = 1 To UBound(arr)
  16.     If d.exists(arr(i, 2)) Then
  17.         n = Range("a65536").End(xlUp).Row
  18.         If Cells(n, 1) = arr(i, 1) - 1 Then n = n + 1 Else n = n + 2
  19.         Cells(i + 5, 1).Resize(1, 2).Cut Cells(n, 1)
  20.     End If
  21. Next
  22. Range("a6").Resize(UBound(arr), 2).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  23. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 09:23 , Processed in 0.553404 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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