有没有办法使多步骤工作表更改宏起作用?

时间:2019-05-17 20:05:20

标签: excel vba

我正在构建一个简单的概念证明库存管理系统。为了简化步骤,我将excel vba的事件更改功能与工作表上的私人下标一起使用。处理流程应如下所示:将工单号扫描到单元格I2中,从而触发要选择的单元格L4。在范围L4:L13中输入内容后,它将移至下一列。单元格O4更改后,它将启动另一个宏以更新条目数据库。问题在于,当更改单元格I2时,什么也没有发生。

我尝试创建多个更改事件专用下标,但这没用。

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim WorkOrder As Range
    Dim MoveTo As Range
    Dim ChangeStatus As Range
    Dim ChangeComplete As Range


    Set WorkOrder = Range("I2")
    Set MoveTo = Range("L4:L13")
    Set ChangeStatus = Range("M4:M13")
    Set ChangeComplete = Range("O4")

    If Not Application.Intersect(WorkOrder, Range(Target.Address)) _
           Is Nothing Then

                Range("L4").Select

    ElseIf Not Application.Intersect(MoveTo, Range(Target.Address)) Is Nothing Then

                Range("M4").Select

    ElseIf Not Application.Intersect(ChangeComplete, Range(Target.Address)) Is Nothing Then

        Call Module1.EditWorkOrderStatus

    End If

Range("i2").Select


End Sub

我希望module1中的宏能够运行并清除所有已更改的单元格,但是什么也没有发生。目前,我的代码没有收到错误。

更新的代码:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim WorkOrder As Range
    Dim MoveTo As Range
    Dim ChangeStatus As Range
    Dim ChangeComplete As Range


    Set WorkOrder = Range("I2")
    Set MoveTo = Range("L4:L13")
    Set ChangeStatus = Range("M4:M13")
    Set ChangeComplete = Range("O4")

    If Not Application.Intersect(WorkOrder, Target) _
           Is Nothing Then

        If WorkOrder = "" Then

            WorkOrder.Select

        Else

            Range("L4").Select

        End If

    ElseIf Not Application.Intersect(MoveTo, Target) Is Nothing Then

                Range("M4").Select

    ElseIf Not Application.Intersect(ChangeComplete, Target) Is Nothing Then

        If ChangeComplete = "" Then

        Else

        Call Module1.EditWorkOrderStatus

        Range("o4").ClearContents
        Range("i2").Select
        End If

    End If



End Sub

1 个答案:

答案 0 :(得分:0)

您可以尝试:

If Not Application.Intersect(Target, Me.Range("I2")) Is Nothing Then