首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >我的VBA代码不工作,错误信息“编译错误:无效的外部过程”

我的VBA代码不工作,错误信息“编译错误:无效的外部过程”
EN

Stack Overflow用户
提问于 2019-06-24 11:34:30
回答 1查看 111关注 0票数 0

我正在创建一个为2019年编译的数据列表。我想消除excel数据中的非活动行,并将它们移到一个标题为“非活动(12个月)”的单独工作表中。我将activity列放置为A,我将列出"Inactive“或将其保留为空。

我将代码复制到新的excel工作表中,并试图保存它,但当我按alt-F8组合键时,我也看不到保存的vba代码,它也不能运行。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-24 12:18:17

在你发布的代码中似乎没有任何东西可以解释“无效的外部过程”。你还有其他代码没有发布吗?

像这样的东西应该是有效的:

代码语言:javascript
复制
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")

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56729541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档