可以透過 VBA(Visual Basic for Applications)來達成這個功能,因為 Excel 本身的儲存格公式無法在輸入後直接覆蓋使用者輸入的數值。以下是你可以使用的 VBA 程式碼:
步驟:
在 Excel 中按 Alt + F11 開啟 VBA 編輯器。
在左側選擇你目前的工作表(例如:Sheet1)。
在右側的編輯區貼上以下程式碼:
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$1" Then Application.EnableEvents = False If IsNumeric(Target.Value) And Target.Value <> "" Then Target.Value = Target.Value + Range("B1").Value End If Application.EnableEvents = True End If End Sub
在Excel中,儲存格A1通常是用來輸入數值,無法直接修改自身的數值來顯示計算結果。但你可以使用 VBA(Visual Basic for Applications) 來達成這個效果。以下是方法:
開啟VBA編輯器
按 Alt + F11 開啟VBA編輯器。
在 "ThisWorkbook" 或 "工作表" 模組中插入以下代碼:
vba Private Sub Worksheet_Change(ByVal Target As Range) Dim fixedValue As Double fixedValue = Range("B1").Value
' 確保只針對A1儲存格進行計算 If Not Intersect(Target, Me.Range("A1")) Is Nothing Then Application.EnableEvents = False Target.Value = Target.Value + fixedValue Application.EnableEvents = True End If End Sub