|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
表名 | 入职日截止 | file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image001.gif | 参数 | 在职人员年龄分布 | | 后勤单位-总经理室,生产单位-工程技术部,生产单位-长晶生产部,生产单位-晶圆生产部,生产单位-动力设备部,生产单位-生管部,生产单位-品保部,后勤单位-采购部,后勤单位-财务部,后勤单位-人力资源部,后勤单位-总经办,后勤单位-业务部,后勤单位-基建处 | 20岁以下,21-25岁,26-30岁,31-35岁,36-40岁,41-50岁,51岁以上 | 在职人员司龄分布 | | 后勤单位-总经理室,生产单位-工程技术部,生产单位-长晶生产部,生产单位-晶圆生产部,生产单位-动力设备部,生产单位-生管部,生产单位-品保部,后勤单位-采购部,后勤单位-财务部,后勤单位-人力资源部,后勤单位-总经办,后勤单位-业务部,后勤单位-基建处 | 0-3个月,4-16个月,7-12个月,1-2年,2-3年,3-5年,5年以上 | 如表中,年龄与工龄按照参数列的条件进行统计.- Sub 新建工作表()
- On Error Resume Next
- tmp = InputBox("请在文本框中输入新建工作表名称:" & Chr(13) & Chr(13) & "按【确定】增加,否则请按【取消】。", "〖点解点解〗")
- If tmp = "" Then tmp = Sheet3.Name
- For Each n In Sheets
- If tmp = n.Name Then
- tmp = n.Name: k = 1
- Exit For
- End If
- Next
- If k <> 1 Then
- Sheets.Add After:=Sheets(Sheets.Count)
- ActiveSheet.Name = tmp
- End If
- With Sheets(tmp)
- .Cells.Clear
- .Cells.RowHeight = Cells(2, 5)
- .Cells.ColumnWidth = Cells(2, 6)
- .Cells.HorizontalAlignment = xlCenter
- .Cells.VerticalAlignment = xlCenter
- End With
- Dim c As Range
- Dim arr
- arr = Sheet2.UsedRange
- Dim d(1 To 6) As Object
- Set dic = CreateObject("Scripting.Dictionary")
- Set d(1) = CreateObject("Scripting.Dictionary")
- Set d(2) = CreateObject("Scripting.Dictionary")
- Set d(3) = CreateObject("Scripting.Dictionary")
- Set d(4) = CreateObject("Scripting.Dictionary")
- Set d(5) = CreateObject("Scripting.Dictionary")
- Set d(6) = CreateObject("Scripting.Dictionary")
- For i = 2 To UBound(arr)
- If arr(i, 17) = "中专" Or arr(i, 17) = "高中" Then
- arr(i, 17) = "高中(含中专)"
- ElseIf IsNumeric(Application.Match(arr(i, 17), Split(Cells(4, 4), ","), 0)) Then
- arr(i, 17) = arr(i, 17)
- Else: arr(i, 17) = "高中以下"
- End If
- arr(i, 22) = Val(Split(arr(i, 22), "年")) * 12 + Val(Split(Split(arr(i, 22), "年")(1), "月"))
- dic(arr(i, 4)) = dic(arr(i, 4)) + 1
- d(1)(arr(i, 2) & arr(i, 4)) = d(1)(arr(i, 2) & arr(i, 4)) + 1 '年龄
- d(2)(arr(i, 22) & arr(i, 4)) = d(2)(arr(i, 22) & arr(i, 4)) + 1 '司龄
- d(3)(arr(i, 17) & arr(i, 4)) = d(3)(arr(i, 17) & arr(i, 4)) + 1 '学历
- d(4)(arr(i, 12) & arr(i, 4)) = d(4)(arr(i, 12) & arr(i, 4)) + 1 '岗位
- d(5)(arr(i, 6) & arr(i, 4)) = d(5)(arr(i, 6) & arr(i, 4)) + 1 '职等
- d(6)(arr(i, 14) & arr(i, 4)) = d(6)(arr(i, 14) & arr(i, 4)) + 1 '性别
- Next
- m = 5
- For i = 2 To 7
- aj = Split(Cells(i, 3), ",")
- bj = Split(Cells(i, 4), ",")
- ReDim sj(UBound(aj))
- For j = 0 To UBound(aj)
- sj(j) = Split(aj(j), "-")
- Next
- With Sheets(tmp)
- .Cells(m - 3, 2) = Cells(i, 1)
- .Cells(m - 3, 2).Font.Bold = True
- .Cells(m - 2, 1) = Split(Cells(1, 3), "-")(0)
- .Cells(m - 2, 2) = Split(Cells(1, 3), "-")(1)
- .Range(.Cells(m - 2, 1), .Cells(m - 1, 1)).Merge
- .Range(.Cells(m - 2, 2), .Cells(m - 1, 2)).Merge
- With .Cells(m, 1).Resize(UBound(sj) + 1, 2)
- .Value = Application.Transpose(Application.Transpose(sj))
- End With
- With .Cells(m, 2).Resize(UBound(sj) + 1, 1)
- .Font.Bold = True
- .Interior.ColorIndex = Cells(2, 7)
- End With
- For j = 0 To UBound(bj)
- .Cells(m - 2, j * 2 + 3) = bj(j)
- .Range(.Cells(m - 2, j * 2 + 3), .Cells(m - 2, j * 2 + 4)).Merge
- .Cells(m - 1, j * 2 + 3) = "人数"
- .Cells(m - 1, j * 2 + 4) = "占比"
- Next
- .Cells(m - 2, 3 + (UBound(bj) + 1) * 2) = "合计"
- .Range(.Cells(m - 2, 3 + (UBound(bj) + 1) * 2), .Cells(m - 1, 3 + (UBound(bj) + 1) * 2)).Merge
- .Cells(m - 2, 4 + (UBound(bj) + 1) * 2) = "占比"
- .Range(.Cells(m - 2, 4 + (UBound(bj) + 1) * 2), .Cells(m - 1, 4 + (UBound(bj) + 1) * 2)).Merge
- .Cells(m + UBound(sj) + 1, 1) = "合计"
- .Range(.Cells(m + UBound(sj) + 1, 1), .Cells(m + UBound(sj) + 1, 2)).Merge
- Set c = .Range(.Cells(m - 2, 1), .Cells(m + UBound(sj) + 1, 4 + (UBound(bj) + 1) * 2))
- c.Borders.LineStyle = xlContinuous
- c.BorderAround xlContinuous, xlMedium
- .Range(.Cells(m - 2, 1), .Cells(m - 1, 4 + (UBound(bj) + 1) * 2)).Interior.ColorIndex = Cells(2, 8)
- crr = .Range(.Cells(m - 2, 1), .Cells(m + UBound(sj) + 1, 4 + (UBound(bj) + 1) * 2))
- For x = 3 To UBound(crr) - 1
- For y = 3 To UBound(crr, 2) - 3 Step 2
- crr(x, y) = d(i - 1)(crr(1, y) & crr(x, 2))
- crr(x, y + 1) = Format(crr(x, y) / dic(crr(x, 2)), "0.00%")
- crr(x, UBound(crr, 2) - 1) = crr(x, UBound(crr, 2) - 1) + crr(x, y)
- crr(UBound(crr), y) = crr(UBound(crr), y) + crr(x, y)
- crr(UBound(crr), UBound(crr, 2) - 1) = crr(UBound(crr), UBound(crr, 2) - 1) + crr(x, y)
- Next
- Next
- For x = 3 To UBound(crr)
- crr(x, UBound(crr, 2)) = Format(crr(x, UBound(crr, 2) - 1) / Val(crr(UBound(crr), UBound(crr, 2) - 1)), "0.00%")
- Next
- .Cells(m - 2, 1).Resize(UBound(crr), UBound(crr, 2)) = crr
- End With
- m = m + UBound(aj) + 6
- Next
- Cells(10, 3) = arr(6, 22)
- Cells(11, 3) = Val(Split(arr(6, 22), "年").Value)
- Cells(12, 3) = Val(Split(Split(arr(12, 22), "年")(1), "月"))
- End Sub
复制代码
|
|