Excel精英培训网

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

如何删除面板数据中缺失过多的样本

[复制链接]
发表于 2015-8-18 14:19 | 显示全部楼层 |阅读模式
对每个样本数据中TAssets这一列数据中20年数据中缺失达到17,即删除只有小于等于3年数据的样本。并不是只删除缺失年份数据,而是删除该样本的全部数据。求好心大神给予本菜鸟指点!!!!

新建文件夹.rar

154.87 KB, 下载次数: 5

发表于 2015-8-18 15:56 | 显示全部楼层
  1. Sub tt()
  2.     Dim DelRng As Range
  3.     Set d = CreateObject("scripting.dictionary")
  4.     Set d1 = CreateObject("scripting.dictionary")
  5.     arr = [a1].CurrentRegion
  6.     For i = 2 To UBound(arr)
  7.         x = arr(i, 1)
  8.         If Not d.exists(x) Then
  9.             Set d(x) = Rows(i)
  10.         Else
  11.             Set d(x) = Union(d(x), Rows(i))
  12.         End If
  13.         If Len(arr(i, 13)) > 0 Then d1(x) = d1(x) + 1
  14.     Next
  15.     For Each x In d1.keys
  16.         If d1(x) < 3 Then
  17.             If DelRng Is Nothing Then Set DelRng = d(x) Else Set DelRng = Union(DelRng, d(x))
  18.         End If
  19.     Next
  20.     If Not DelRng Is Nothing Then DelRng.Delete
  21. End Sub
复制代码
回复

使用道具 举报

发表于 2015-8-18 15:56 | 显示全部楼层
删除前381行,删除后321行。

新建 Microsoft Excel 工作表.rar

317.98 KB, 下载次数: 0

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-7 17:28 , Processed in 0.289722 second(s), 18 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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