|
- Sub 离职员工()
- Dim arr, brr
- arr = ThisWorkbook.Worksheets("1月").UsedRange '把1月份的数据存入数组
- brr = ThisWorkbook.Worksheets("2月").UsedRange '把2月份的数据存入数组
- Set dic1 = CreateObject("scripting.dictionary")
- Set dic2 = CreateObject("scripting.dictionary")
- For i = 2 To UBound(arr)
- dic1(arr(i, 1)) = "" '把1月员工号存入字典并去重, 当然工号无重复,下面类似
- Next
- For j = 2 To UBound(brr)
- dic2(brr(j, 1)) = ""
- Next
- l = 3
- For k = 2 To UBound(arr) '遍历数组arr,也就是遍历1月员工信息
- If Not dic2.Exists(arr(k, 1)) Then '如果在字典dic2中不存在arr数组中的元素,也就是2月份中不存在的1月份的员工号,也就是离职员工
- ThisWorkbook.Worksheets("结果").Range("A" & l).Resize(1, 5) = Application.Index(arr, k, 0) '第一次进入if结构中时把数组arr的第k行赋值给A3单元格扩展1行5列的区域,以后进入if结构类似,只不过行号加1,也就是赋值在结果表的下一行
- l = l + 1 '赋值完成后行号加1,也就是下一个离职员工的信息在上一个离职员工的下一行
- End If
- Next
- n = 3
- For m = 2 To UBound(brr) '这个循环跟上面的类似,只不过是在dic1中查找brr数组中的元素,也就是查找新入职员工
- If Not dic1.Exists(brr(m, 1)) Then
- ThisWorkbook.Worksheets("结果").Range("H" & n).Resize(1, 5) = Application.Index(brr, m, 0)
- n = n + 1
- End If
- Next
- iRow = ThisWorkbook.Worksheets("结果").[A3].End(xlDown).Row '行号
- With ThisWorkbook.Worksheets("结果").Range("A3:E" & iRow) '居中并加所有边框
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .Borders(xlEdgeLeft).LineStyle = xlContinuous
- .Borders(xlEdgeRight).LineStyle = xlContinuous
- .Borders(xlEdgeTop).LineStyle = xlContinuous
- .Borders(xlEdgeBottom).LineStyle = xlContinuous
- .Borders(xlInsideVertical).LineStyle = xlContinuous
- .Borders(xlInsideHorizontal).LineStyle = xlContinuous
- End With
- jRow = ThisWorkbook.Worksheets("结果").[H3].End(xlDown).Row
- With ThisWorkbook.Worksheets("结果").Range("H3:L" & jRow)
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .Borders(xlEdgeLeft).LineStyle = xlContinuous
- .Borders(xlEdgeRight).LineStyle = xlContinuous
- .Borders(xlEdgeTop).LineStyle = xlContinuous
- .Borders(xlEdgeBottom).LineStyle = xlContinuous
- .Borders(xlInsideVertical).LineStyle = xlContinuous
- .Borders(xlInsideHorizontal).LineStyle = xlContinuous
- End With
- End Sub
复制代码 |
|