繁体   English   中英

不能合并两个 Private Sub Worksheet_Change(ByVal Target As Range)

[英]Cannot combine two Private Sub Worksheet_Change(ByVal Target As Range)

我正在尝试将两个 Private Sub Worksheet_Change(ByVal Target As Range) 合并到同一个工作表中,但第一个仅有效,第二个无效。 我没有从调试中收到任何错误 - 所以我猜它必须是一个简单的调整。 以下是代码 - 提前感谢您帮助我。

Private Sub Worksheet_Change(ByVal Target As Range)

    'Auto Re-sort of Entire entry based on change in Due Date

    Dim Table As ListObject
    Dim SortCol As Range

    Set Table = ActiveSheet.ListObjects("Table1")
    Set SortCol = Range("Table1[Due Date]")

    If Not Intersect(Target, SortCol) Is Nothing Then
        With Table.Sort
            .SortFields.Clear
            .SortFields.Add Key:=SortCol, Order:=xlAscending
            .Header = xlYes
            .Apply
        End With
    End If

    'Automating the Move Entire Row Based on Value being "Completed", from Tasks 
    worksheet to Completed Worksheet

    Dim Z As Long
    Dim xVal As String
    On Error Resume Next
        If Intersect(Target, Range("H:H")) Is Nothing Then
        Application.EnableEvents = False
        For Z = 1 To Target.Count
            If Target(Z).Value > 0 Then
                Call MoveBasedOnValue
            End If
        Next
        Application.EnableEvents = True
        End If
End Sub

也许我不太了解你的问题,但是……你为什么不放一个Private Sub Worksheet_Change(ByVal Target As Range) 然后,让它根据需要调用尽可能多的其他函数:

Private Sub Worksheet_Change(ByVal Target As Range)
     sub1 Target

     sub2 Target
End Sub

Private Sub sub1(ByVal Target As Range)
    'Replace with the code of your first function:
    MsgBox "Hello from sub1"
End Sub

Private Sub sub2(ByVal Target As Range)
    'Replace with the code of your second function:
    MsgBox "Hello from sub2"
End Sub


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM