返回列表 上一主題 發帖

[發問] Worksheet_Change合併

[發問] 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

請問有辦法簡單讓上面二個工作表的程式碼合併執行嗎?
謝謝~

回復 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
用行動裝置瀏覽論壇學習很方便,謝謝論壇經營團隊
請大家一起上論壇來交流

TOP

回復 2# Andy2483


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

   

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

TOP

        靜思自在 : 好事要提得起,是非要放得下,成就別人即是成就自己。
返回列表 上一主題