Мой код VBA не работает, сообщение об ошибке «Ошибка компиляции: недопустимая внешняя процедура» - PullRequest
0 голосов
/ 24 июня 2019

Я создаю список данных, собранных за 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

1 Ответ

0 голосов
/ 24 июня 2019

Кажется, в вашем размещенном коде нет ничего, что могло бы объяснить "недопустимую внешнюю процедуру". У вас есть другой код, который вы не опубликовали?

Примерно так должно работать:

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
        Target.Resize(1, 2).Cut _
          Sheets("Inactive(12mths").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
        Application.EnableEvents = True
    End If

End Sub

Здесь есть опечатка Sheets("Inactive(12mths")?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...