Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 单元停止计算_Excel_Vba - Fatal编程技术网

Excel 单元停止计算

Excel 单元停止计算,excel,vba,Excel,Vba,对Excel中的VBA非常陌生,被要求对单元格更改进行一些验证,但有点卡住了 所以,用户需要在单元格中输入一个货币值,比如说D16,所以我想我应该挂接工作表上的_Change事件,它工作得很好 但是,当一个条目提交到D16中时,我需要工作表的其余部分不完成计算,基本上,当输入500000时,其他单元格将使用另一个工作表中的值进行更新 我的代码 Private Sub Worksheet_Change(ByVal Target As Range) If Target = Range("D

对Excel中的VBA非常陌生,被要求对单元格更改进行一些验证,但有点卡住了

所以,用户需要在单元格中输入一个货币值,比如说D16,所以我想我应该挂接工作表上的_Change事件,它工作得很好

但是,当一个条目提交到D16中时,我需要工作表的其余部分不完成计算,基本上,当输入500000时,其他单元格将使用另一个工作表中的值进行更新

我的代码

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target = Range("D16") Then

       Dim numeric
       numeric = IsNumeric(Target)


       If numeric = False Then

          MsgBox "error"
          Exit Sub

          /// this is where I need to "stop" the calculations from firing

       End If

    End If

End Sub

使用
Application.Calculation=xlCalculationManual


别忘了再次打开它:
Application.Calculation=xlCalculationAutomatic

,我希望下面的代码能有所帮助。您需要将其粘贴到“工作表代码”部分

Private Sub Worksheet_Change(ByVal Target As Range)

    On Error Resume Next

    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual

    Dim rng As Range
    Set rng = Range("D16")

    If Not Intersect(Target, rng) Is Nothing And IsNumeric(Target) Then

        If Target.Value >= 500000 Then
            MsgBox "Value is greater than 500000"
        End If


    End If


    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
End Sub

@桑托什,是的,这两个都不能解决我们的问题。我们最后连接了每个可用的事件,并在每个事件中调用了工作表_Change事件。奇怪的情况,我知道,我无法解释为什么,但它奏效了。