运行 宏,如果更改了非连续范围内的任何单元格

Run macro if any cell in a non-contiguous range are changed

我有一个不连续的范围,我需要 运行 一个 privatesub,如果这个单元格中的任何一个发生变化,但前提是这个范围内的所有单元格都不为空我已经试过了但是不是无法正常工作,因为即使单元格为空,它也会 运行 启用宏,此处:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D3")) Is Nothing Then

    If (ActiveSheet.Range("D3") <> """") And (ActiveSheet.Range("D5") <> """") And _
       (ActiveSheet.Range("I3") <> """") And (ActiveSheet.Range("O3") <> """") And _
       (ActiveSheet.Range("O5") <> """") And (ActiveSheet.Range("O7") <> """") And _
       (ActiveSheet.Range("X3") <> """") And (ActiveSheet.Range("X5") <> """") _
    Then

    Create

    End If
End If
End Sub

感谢您的宝贵时间=]

我认为这应该可以满足您的要求:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    Set rng = Range("D3,D5,I3,O3,O5,O7,X3,X5")
    If Intersect(Target, rng) Is Nothing Then Exit Sub
    For Each r In rng
        If r.Value = "" Then
            Exit Sub
        End If
    Next r
    MsgBox "I am going to do something"
End Sub