![](/img/trans.png)
[英]VBA code to show Message Box popup if the formula in the target cell exceeds a certain value
[英]VBA code to show message box popup if the formula in the target column exceeds a certain value
我在此網站上找到了特定單元格的代碼
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") > 0.5 Then
MsgBox "Discount too high"
End If
End Sub
但是我想知道是否有可能使整個列而不是一個特定的單元格都可以進行這項工作?
嘗試使用此事件代碼:
Private Sub Worksheet_Calculate()
Dim rr As Range, r As Range
Set rr = Range("A:A").Cells.SpecialCells(xlCellTypeFormulas)
For Each r In rr
If r.Value > 0.5 Then
MsgBox "Discount too high"
End If
Next r
End Sub
編輯#1:
如果要將消息限制為一行,請刪除第一個子並將其替換為:
Private Sub Worksheet_Change(ByVal Target As Range)
rt = Target.Row
If Range("A" & rt) > 0.5 Then
MsgBox "Discount too high"
End If
End Sub
我會說這是在Excel中做事的錯誤方式:)。
我可以提出以下建議:1.根據值,例如> 0.5,將條件格式添加到單元格中。2.在該單元格旁邊的單元格中添加一個簡單的IF公式,該公式表示錯誤。
使用事件將抑制撤消操作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.