Я создаю список данных, собранных за 2019 год. И я хочу исключить НЕАКТИВНЫЕ строки в моих данных Excel и переместить их на отдельную рабочую таблицу под названием «Неактивно (12 месяцев)». Я поместил свой столбец активности как A, где я буду перечислять «Неактивный» или оставить пустым.
Я скопировал код на новый лист Excel и попытался сохранить его, но когда я нажимаю alt-F8, я тоже не вижу сохраненный код vba, и он не запускается.
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 будет запускаться автоматически при открытии листа, но он не автоматизирует себя. Я не уверен, что спас это неправильно. = (
25июнь19 (обновление)
Я переписал цитату, но все еще не могу заставить ее работать на моем листе Excel, с поддержкой макросов ...
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