Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
' Only react to edits in Column A: '
If Not Intersect(Target, Sheets("Buyer Limit").Range("A:A")) Is Nothing Then
' Dont do anything if > 1 cell was just changed: '
If Target.Cells.Count = 1 Then
' Only make the change if the new value in Col A is "inactive": ' If Target.Value = "Inactive" Then
' Find the next available cell on the Inactive(12mths) sheet for a name: '
Dim nextRange As Range
Set nextRange = Sheets("Inactive(12mths").Range("A65536").End(xlUp).Offset(1, 0)
' Cut the employee name and status and paste onto the Inactive(12mths) sheet: '
Range(Target, Target.Offset(0, -1)).Cut
Sheets("Buyer Limit").Paste Destination:=Sheets("Inactive(12mths").Range(nextRange.Address)
End If
End If
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
我希望此vba代码的输出在我打开工作表时自动运行,但它不会自动运行。我不确定我是不是保存错了。=(
19年6月25日(更新)
我已经重写了引文,但我仍然不能让它在我的excel工作表上工作,启用宏...
代码语言:
javascript
复制
Private Sub Worksheet_Activate(ByVal Target As Range)
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
' Only react to edits in Column A: '
If Not Intersect(Target, Sheets("Buyer").Range("A:A")) Is Nothing Then
' Dont do anything if > 1 cell was just changed: '
If Target.Cells.Count = 1 Then
' Only make the change if the new value in Col A is "Inactive": '
If Target.Value = "Inactive" Then
' Find the next available cell on the Inactive sheet for a name: '
Dim nextRange As Range
Set nextRange = Sheets("Inactive").Range("A65536").End(xlUp).Offset(1, 0)
' Cut the CP name and status and paste onto the Inactive sheet: '
Range(Target, Target.Offset(0, -1)).Cut
Sheets("Buyer").Paste Destination:=Sheets("Inactive").Range(nextRange.Address)
End If
End If
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Column = 1 and Target.Value = "Inactive" then
Application.EnableEvents = False