|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Option Explicit
- Private Sub Worksheet_Change(ByVal Target As Range)
- On Error Resume Next '设置错误处理
- Dim wstLZ As Worksheet, wstTX As Worksheet, intR%, j%
- Set wstLZ = Sheets("离职表")
- Set wstTX = Sheets("退休表")
- Application.ScreenUpdating = False '关闭屏幕刷新
- If Target.Cells.Count = 1 Then
- If Target.Column = 6 And Target.Row > 1 And Len(Target.Value) > 0 And Cells(Target.Row, 6) = "离职" Then
- Select Case Target.Value
- Case "离职"
- intR = wstLZ.[A65536].End(xlUp).Row + 1 '获取离职表可添数据行号
- Target.EntireRow.Copy wstLZ.Cells(intR, 1) '复制到离职表
- wstLZ.Cells(intR, Target.Column).Interior.ThemeColor = 8
- End Select
- Target.EntireRow.Delete '删除当前行
- ElseIf Target.Column = 6 And Target.Row > 1 And Len(Target.Value) > 0 And Cells(Target.Row, 6) = "退休" Then
- Select Case Target.Value
- Case "退休"
- intR = wstLZ.[A65536].End(xlUp).Row + 1
- Target.EntireRow.Copy wstLZ.Cells(intR, 1)
- wstLZ.Cells(intR, Target.Column).Interior.ThemeColor = 10
- With wstTX '提取数据到退休表
- intR = .[A65536].End(xlUp).Row + 1 '获取退休表可添数据行号
- .Cells(intR, 1).Formula = "=ROW()-1" '写入序号公式
- For j = 2 To .[A1].End(xlToRight).Column '使用循环匹配表头对应数据
- .Cells(intR, j) = Cells(Target.Row, [1:1].Find(.Cells(1, j), LookIn:=xlValues).Column)
- Next
- .Cells(intR, .[1:1].Find("状态", LookIn:=xlValues).Column).Interior.ThemeColor = 10
- End With
- End Select
- Target.EntireRow.Delete '删除当前行
- '设置边框线
- wstLZ.[A1].CurrentRegion.Borders.LineStyle = xlContinuous
- wstTX.[A1].CurrentRegion.Borders.LineStyle = xlContinuous
- End If
- End If
- '释放资源
- Set wstLZ = Nothing
- Set wstTX = Nothing
- Application.ScreenUpdating = True '打开屏幕刷新
- End Sub
复制代码 不知道我这样修改的对不对,但是《在职表》移到《离职表》删除B列那个我就不会啦,希望得到您的指点~
|
|