RE:顯示公式中直接資料輸入或儲存格值的最大值

RE:顯示公式中直接資料輸入或儲存格值的最大值

參考: Excel - 如何直接輸入資料或從公式中取得儲存格值

我想諮詢一下相關問題。如果我想將現有的公式值與新的輸入值進行比較,我將如何編輯我的 VBA 公式。並顯示制定的輸入值和新輸入值的最大值。

非常感謝您的熱情幫助。不勝感激。

答案1

根據您的原始請求:如果 A2 和 A3 都有數值,則 A4 將填充它們的總和。如果它們是非數字或空,則 A4 將顯示錯誤。如果 A4 被覆蓋,則該值將是永久的,直到 A2 或 A3 再次變更為止。新增的要求:如果 A2 和 A3 為 A4 產生了一個很好的和,並且有人用新的數值覆蓋了 A4,那麼您希望在 A2+A3 和 A4 之間取最大值。我認為這應該顯示在單元格 A5 中。

在原來的答案基礎上補充: Private Sub Worksheet_Change(ByVal Target As Excel.Range) If Not Intersect(Target, Range("A2:A3")) Is Nothing Then If WorksheetFunction.Count(Range("A2:A3")) = 2 Then Range("A4").Formula = "=A2+A3" End If ElseIf Not (Intersect(Target, Range("A4"))) Is Nothing Then 'Check for numbers in a2, a3, and a4 If IsNumeric(Range("A2").Value) And IsNumeric(Range("A3").Value) And IsNumeric(Range("A4").Value) Then 'If a2+a3 is greater than a4 If Range("A2").Value + Range("A3").Value > Range("A4").Value Then 'set the sum of a2 and a3 to cell a5 Range("A5").Value = Range("A2").Value + Range("A3").Value Else 'set the value of cell a4 to cell a5 Range("A5").Value = Range("A4").Value End If End If End If End Sub

相關內容