|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim reg As New RegExp
- Set d = CreateObject("scripting.dictionary")
- With reg
- .Global = True
- .Pattern = "(\d+\.)?\d+"
- End With
- With Worksheets("工资计算基数")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a3:b" & r)
- ReDim brr(1 To UBound(arr), 1 To 2)
- For i = 1 To UBound(arr)
- Set mh = reg.Execute(arr(i, 1))
- If mh.Count = 1 Then
- brr(i, 1) = Val(mh(0))
- Else
- brr(i, 1) = Val(mh(1))
- End If
- brr(i, 2) = arr(i, 2)
- Next
- brr(UBound(brr), 1) = 10 ^ 8
- End With
- For Each ws In Worksheets
- If ws.Name <> "汇总表" And ws.Name <> "工资计算基数" Then
- With ws
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- s = 0
- For i = 2 To UBound(arr)
- arr(i, UBound(arr, 2)) = Empty
- For j = 2 To UBound(arr, 2) - 3 Step 3
- arr(i, j + 1) = Empty
- For k = 1 To UBound(brr)
- If arr(i, j) <= brr(k, 1) Then
- arr(i, j + 1) = brr(k, 2)
- Exit For
- End If
- Next
- arr(i, UBound(arr, 2)) = arr(i, UBound(arr, 2)) + arr(i, j + 1)
- Next
- s = s + arr(i, UBound(arr, 2))
- Next
- d(ws.Name) = s
- .Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
- End With
- End If
- Next
- With Worksheets("汇总表")
- .UsedRange.Offset(1, 0).Clear
- With .Range("a2").Resize(d.Count, 2)
- .Value = Application.Transpose(Array(d.keys, d.items))
- .Borders.LineStyle = xlContinuous
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|