如何合并两个具有不同触发器的工作表与工作表上的“私有工作表_更改”

时间:2018-11-22 02:27:04

标签: excel vba

我有2个私人子worksheet_change子,它们需要在同一张纸上,无法弄清楚如何将它们组合在一起。整个vba游戏和我在各个网站上找到的两个潜艇都非常新颖。任何帮助将不胜感激。下面是2条代码。一个获取单元格更改的时间,另一个获取另一个单元格更改时的消息框(自第一篇文章以来已更新。两者都是worksheet_change子

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rCell As Range
Dim rChange As Range

On Error GoTo ErrHandler
Set rChange = Intersect(Target, Range("A:A"))
If Not rChange Is Nothing Then
    Application.EnableEvents = False
    For Each rCell In rChange
        If rCell > "" Then
            With rCell.Offset(0, 1)
                .Value = Now
                .NumberFormat = "hh:mm:ss"
            End With
        Else
            rCell.Offset(0, 1).Clear
        End If
    Next
End If

ExitHandler:
    Set rCell = Nothing
Set rChange = Nothing
Application.EnableEvents = True
Exit Sub
ErrHandler:
    MsgBox Err.Description
    Resume ExitHandler

End Sub

第二个是

Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Range("AH4"), Target) Is Nothing) Then
    MsgBox "Broadcast Now!"
End If

End Sub

0 个答案:

没有答案