|
- <p>Option Explicit</p><p>
- </p><p>Private Sub Worksheet_Change(ByVal Target As Range)</p><p>On Error Resume Next '设置错误处理</p><p>Dim wstLZ As Worksheet, wstTX As Worksheet, intR%, j%</p><p>Set wstLZ = Sheets("离职表")</p><p>Set wstTX = Sheets("退休表")</p><p>Application.ScreenUpdating = False '关闭屏幕刷新</p><p>If Target.Cells.Count = 1 Then</p><p> If Target.Column = 6 And Target.Row > 1 And Len(Target.Value) > 0 Then</p><p> Select Case Target.Value</p><p> Case "离职"</p><p> intR = wstLZ.[A65536].End(xlUp).Row + 1 '获取离职表可添数据行号</p><p> Target.EntireRow.Copy wstLZ.Cells(intR, 1) '复制到离职表</p><p> wstLZ.Cells(intR, Target.Column).Interior.ThemeColor = 8</p><p> Case "退休"</p><p> intR = wstLZ.[A65536].End(xlUp).Row + 1</p><p> Target.EntireRow.Copy wstLZ.Cells(intR, 1)</p><p> wstLZ.Cells(intR, Target.Column).Interior.ThemeColor = 10</p><p> With wstTX '提取数据到退休表</p><p> intR = .[A65536].End(xlUp).Row + 1 '获取退休表可添数据行号</p><p> .Cells(intR, 1).Formula = "=ROW()-1" '写入序号公式</p><p> For j = 2 To .[A1].End(xlToRight).Column '使用循环匹配表头对应数据</p><p> .Cells(intR, j) = Cells(Target.Row, [1:1].Find(.Cells(1, j), LookIn:=xlValues).Column)</p><p> Next</p><p> .Cells(intR, .[1:1].Find("状态", LookIn:=xlValues).Column).Interior.ThemeColor = 10</p><p> End With</p><p> End Select</p><p> Target.EntireRow.Delete '删除当前行</p><p> '设置边框线</p><p> wstLZ.[A1].CurrentRegion.Borders.LineStyle = xlContinuous</p><p> wstTX.[A1].CurrentRegion.Borders.LineStyle = xlContinuous</p><p> End If</p><p>End If</p><p>'释放资源</p><p>Set wstLZ = Nothing</p><p>Set wstTX = Nothing</p><p>Application.ScreenUpdating = True '打开屏幕刷新</p><p>End Sub</p>
复制代码
|
|