|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
修正了一下。可以在空白表上直接生成姓名和违规类型。
3楼代码由于源数据问题,“说闲话”统计不准(共24个,有8个统计到“次说闲话”中去了)。
- Sub 统计()
- Set d = CreateObject("scripting.dictionary")
- Set dlx = CreateObject("scripting.dictionary") '对于违规类型字典
- kk = 3
- Dim ar(1 To 10000, 1 To 50)
- With CreateObject("vbscript.regexp")
- .Global = True
- .Pattern = "([\u4e00-\u9fa5]+)(\d+)" '找到 “迟到1”这种内容
- For Each sh In Sheets
- If InStr(sh.Name, "月") > 0 Then
- br = sh.[a1].CurrentRegion
- For i = 2 To UBound(br)
- x = Trim(br(i, 2))
- If x <> "" Then
- If Not d.exists(x) Then
- k = k + 1
- d(x) = k
- For j = 1 To 3: ar(k, j) = br(i, j): Next j
- End If
- p = d(x)
- For j = 4 To UBound(br, 2)
- s = Trim(br(i, j))
- s = Replace(s, "次", "次/") '源数据里有误,用代码修正一下,不然会出现“次说闲话”的违规类型。
- If .test(s) <> "" Then
- For Each m In .Execute(s)
- lx = m.submatches(0) '违规类型
- cs = Val(m.submatches(1)) '违规次数
- If Not dlx.exists(lx) Then kk = kk + 1: dlx(lx) = kk
- c = dlx(lx)
- ar(p, c) = ar(p, c) + cs
- Next m: End If: Next j: End If: Next i: End If: Next sh
- End With
-
- With Sheets("统计")
- .Cells.ClearContents
- .[a1].Resize(1, 3) = Array("姓名", "编号", "性别")
- .[d1].Resize(1, dlx.Count) = dlx.keys
- .[a2].Resize(k, dlx.Count + 3) = ar
- End With
- MsgBox "ok!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|