|
- Sub test()
- Dim sht As Worksheet
- Dim FindSht As Boolean
- Dim MyRow%
- MyRow = Sheets("新员工名单").[a1].End(xlDown).Row
-
- '添加新来的
- For i = 2 To MyRow
- FindSht = False
- For Each sht In Sheets
- If sht.Name = Sheets("新员工名单").Cells(i, 1).Value Then FindSht = True
- Next
-
- If Not FindSht Then
- Sheets("老员工").Copy after:=Sheets(Sheets.Count)
- Set sht = Sheets(Sheets.Count)
- sht.Name = Sheets("新员工名单").Cells(i, 1).Value
- End If
- Next
-
- '删除不在的
- Dim arrTmp() As String
-
- For i = Sheets.Count To 1 Step -1
- 'Debug.Print sht.Name
- FindSht = False
- For j = 2 To MyRow
- If Sheets(i).Name = Sheets("新员工名单").Cells(j, 1).Value Then FindSht = True
- Next
-
- If Not FindSht Then '如果扫描一遍员工名单没发现工作表名字在其中
- '就进一步检查此工作表名字是否在不能删的工作表名字中
- arrTmp = Filter(Array("新员工名单", "老员工", "不能删1", "不能删2", "不能删3"), Sheets(i).Name)
- Application.DisplayAlerts = False
- If UBound(arrTmp) = -1 Then Sheets(i).Delete '如果是空数组,说明此表可删
- Application.DisplayAlerts = True
- End If
- Next
-
- MsgBox "OK"
- End Sub
复制代码 |
|