[英]Combine two 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.