|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 生成社保表()
- Dim d As New Dictionary
- Dim arr, brr()
- Dim r%, i%
- With Worksheets("数据源")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:k" & r)
- End With
- ReDim brr(1 To 16, 1 To 1)
- m = 0
- For i = 1 To UBound(arr)
- If Not d.Exists(arr(i, 2)) Then
- m = m + 1
- ReDim Preserve brr(1 To 16, 1 To m)
- brr(2, m) = arr(i, 2)
- brr(3, m) = arr(i, 3)
- brr(4, m) = arr(i, 5)
- d(arr(i, 2)) = m
- End If
- n = d(arr(i, 2))
- Select Case arr(i, 1)
- Case "城镇职工基本医疗保险"
- brr(6, n) = arr(i, 6)
- brr(12, n) = arr(i, 9)
- Case "大病医疗救助"
- brr(14, n) = arr(i, 9)
- Case "工伤保险"
- brr(8, n) = arr(i, 6)
- Case "企业基本养老保险"
- brr(5, n) = arr(i, 6)
- brr(11, n) = arr(i, 9)
- Case "生育保险"
- brr(9, n) = arr(i, 6)
- Case "失业保险"
- brr(7, n) = arr(i, 6)
- brr(13, n) = arr(i, 9)
- End Select
- Next
- brr = Application.Transpose(brr)
- For i = 1 To UBound(brr)
- brr(i, 1) = i
- For j = 5 To 9
- brr(i, 10) = brr(i, 10) + brr(i, j)
- Next
- For j = 11 To 14
- brr(i, 15) = brr(i, 15) + brr(i, j)
- Next
- brr(i, 16) = brr(i, 10) + brr(i, 15)
- Next
- With Worksheets("社保表")
- .UsedRange.Offset(2, 0).Delete
- .Range("a3").Resize(UBound(brr), UBound(brr, 2)) = brr
- .Range("a1").CurrentRegion.Borders.LineStyle = xlContinuous
- End With
- End Sub
复制代码 |
|