|
不知能不能用
Sub lx()
Dim ar, br, i%, j%, d As Object, wb1 As Workbook, wb As Workbook
Set wb1 = ThisWorkbook
ar = wb1.Sheets(1).UsedRange
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(ar)
For j = 2 To UBound(ar, 2)
If j <= 4 Then
d(ar(i, 1) & "-" & ar(1, j)) = ar(i, j)
Else
d(ar(i, 1) & "-" & Left(ar(1, j), 3)) = ar(i, j)
End If
Next j
Next i
Set wb = Workbooks.Open(wb1.Path & "\模板表.xls")
For m = 1 To UBound(ar) - 1
br = wb.Sheets(1).Range("a6:d17")
For i = 1 To UBound(br)
For j = 1 To UBound(br, 2)
Select Case Trim(br(i, j))
Case "员工姓名"
br(i + 1, j) = ar(m + 1, 1)
Case "入职日期"
br(i + 1, j) = d(ar(m + 1, 1) & "-" & Trim(br(i, j)))
Case "所属部门"
br(i + 1, j) = d(ar(m + 1, 1) & "-" & Trim(br(i, j)))
Case "职位"
br(i + 1, j) = d(ar(m + 1, 1) & "-" & Trim(br(i, j)))
Case "调整前"
br(i + 4, j) = d(ar(m + 1, 1) & "-" & Trim(br(i, j)))
Case "调整后"
br(i + 4, j) = d(ar(m + 1, 1) & "-" & Trim(br(i, j)))
End Select
Next j
Next i
Set wb2 = Workbooks.Add
wb.Sheets(1).Copy wb2.Sheets(1)
wb2.Sheets(1).[a6].Resize(UBound(br), UBound(br, 2)) = br
wb2.SaveAs (wb1.Path & "\薪酬变动申请表" & "-" & ar(m + 1, 1) & ".xlsx")
wb2.Close
Next m
End Sub |
|