Worksheet_Calculate on multiple ranges

前端 未结 1 1707
情书的邮戳
情书的邮戳 2020-12-21 22:38

I have the current code calculating a single cell\'s value then calling a module if it\'s value exceeds another value.

How can I make it check multiple ranges of cel

相关标签:
1条回答
  • 2020-12-21 22:55

    Is this what you are trying?

    Private Sub Worksheet_Calculate()
        Dim aRng As Range, bRng As Range
        Dim aCell As Range
    
        Set aRng = Range("B5:E5")
        Set bRng = Range("B8:M8")
    
        For Each aCell In aRng
            If aCell.Value > 4 Then
                '
                Application.Run "Mail_small_Text_Outlook"
                '
                Exit Sub
            End If
        Next
    
        For Each aCell In bRng
            If aCell.Value > 4 Then
                '
                Application.Run "Mail_small_Text_Outlook"
                '
                Exit Sub
            End If
        Next
    End Sub
    

    or something like this?

    Private Sub Worksheet_Calculate()
        Dim aRng As Range, bRng As Range
        Dim aCell As Range, uRng As Range
    
        Set aRng = Range("B5:E5")
        Set bRng = Range("B8:M8")
        Set uRng = Union(aRng, bRng)
    
        For Each aCell In uRng
            If aCell.Value > 4 Then
                '
                Application.Run "Mail_small_Text_Outlook"
                '
                Exit Sub
            End If
        Next
    End Sub
    
    0 讨论(0)
提交回复
热议问题