|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
参与一下
- Sub t()
- Dim arr, brr, v, ma, mi, m%, dic, r%, sh, av, ta, ti, res, h, k, ro%, rr%, q, wb
- Set dic = CreateObject("scripting.dictionary")
- With Sheets("数据")
- m = .[a1].End(4).Row
- arr = .Range("a2:d" & m)
- For i = 1 To UBound(arr)
- dic(arr(i, 1)) = ""
- Next i
- ReDim brr(1 To dic.Count, 1 To 4)
- rr = 1
- For Each k In dic.keys
- r = WorksheetFunction.CountIf(.[a:a], k)
- ad = .[a:a].Find(what:=k).Address
- Set sh = .Range(ad).Resize(r, 4)
- q = r
- If r < 3 Then
- v = WorksheetFunction.Average(sh(1, 2).Resize(r, 1))
- Else
- ma = WorksheetFunction.Max(sh(1, 2).Resize(r, 1))
- mi = WorksheetFunction.Min(sh(1, 2).Resize(r, 1))
- If ma - mi < 21 Then
- v = WorksheetFunction.Average(sh(1, 2).Resize(r, 1))
- Else
- av = WorksheetFunction.Average(sh(1, 2).Resize(r, 1))
- ta = Abs(ma - av)
- ti = Abs(mi - av)
- res = WorksheetFunction.Max(ta, ti)
- If ti = res Then h = mi Else h = ma
- Set k1 = sh(1, 2).Resize(r, 1).Find(what:=h, lookat:=xlWhole)
- Do While Not k1 Is Nothing
- ro = k1.Row
- Rows(ro).Delete
- q = q - 1
- Set k1 = sh(1, 2).Resize(q, 1).Find(what:=h, lookat:=xlWhole)
- Loop
- End If
- End If
- Set wb = .Range(ad).Resize(q, 4)
- If Not wb Is Nothing Then
- brr(rr, 1) = k
- brr(rr, 2) = wb(1, 3)
- brr(rr, 3) = WorksheetFunction.CountIf(.[a:a], k)
- brr(rr, 4) = WorksheetFunction.Average(wb(1, 2).Resize(q, 1))
- rr = rr + 1
- End If
- Set sh = Nothing
- Set wb = Nothing
- Set k1 = Nothing
- Next k
- .[k2].Resize(UBound(brr), 4) = brr
- End With
- Set dic = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|