Jad*_*ric 8 excel vba excel-vba
在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
Run Code Online (Sandbox Code Playgroud)
San*_*osh 18
我希望下面的代码有帮助.您需要将其粘贴到表单代码部分.
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
Run Code Online (Sandbox Code Playgroud)
Bat*_*eba 11
使用Application.Calculation = xlCalculationManual.
别忘了再次打开它:Application.Calculation = xlCalculationAutomatic.