Board logo

標題: [發問] Worksheet_Change合併 [打印本頁]

作者: wayne0303    時間: 2023-10-23 13:58     標題: Worksheet_Change合併

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xA As Range, xR As Range
Set xA = Intersect(Target, Range("U:U"))
If xA Is Nothing Then Exit Sub
Application.ScreenUpdating = False
For Each xR In xA
    Range(Cells(xR.Row, 1), Cells(xR.Row, 22)).Font.ColorIndex = 15 ^ -(xR > 1)
Next
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
Dim xA As Range, xR As Range
Set xA = Intersect(Target, Range("O:O"))
If xA Is Nothing Then Exit Sub
Application.ScreenUpdating = False
For Each xR In xA
    Range(Cells(xR.Row, 16), xR).Font.ColorIndex = 2 ^ -(xR = "")
Next
End Sub

請問有辦法簡單讓上面二個工作表的程式碼合併執行嗎?
謝謝~
作者: Andy2483    時間: 2023-10-23 14:19

回復 1# wayne0303

這兩程序有交互影響結果:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xA As Range, xR As Range
Application.ScreenUpdating = False
Set xA = Intersect(Target, Range("U:U"))
If xA Is Nothing Then GoTo xA0
For Each xR In xA
    Range(Cells(xR.Row, 1), Cells(xR.Row, 22)).Font.ColorIndex = 15 ^ -(xR > 1)
Next
xA0:
Set xA = Intersect(Target, Range("O:O"))
If xA Is Nothing Then Exit Sub
For Each xR In xA
    Range(Cells(xR.Row, 16), xR).Font.ColorIndex = 2 ^ -(xR = "")
Next
End Sub
作者: wayne0303    時間: 2023-10-23 15:05

回復 2# Andy2483


    這兩程序有交互影響結果: ??
    它們觸發的儲存欄&條件是不同的,因為希望有可以回復的動作,所以才想合併在一起

   

    執行結果是可以的~
    謝謝Andy大~




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)