Make Excel Cell B1 Return A1 or Its Negative with VBA
Question details
Replace an entry of 1 or -1 in Excel cell B1 with the corresponding value calculated from A1.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user wants to enter a multiplier in B1 and have VBA replace it with A1 or its negative without using a separate calculation cell.
- Observed behavior
- Entering 1 in B1 should return A1, while entering -1 should return the opposite of A1.
Open the workbook in a desktop version of Excel that supports VBA, and make sure A1 contains a number. Check that you can access the sheet's code module and are allowed to enable macros for this workbook.
Use a Worksheet_Change macro in the worksheet module
Use this event macro to replace a single entry of 1 or -1 in B1 with the result of multiplying it by A1.
The entry is a multiplier: 1 returns A1 unchanged, and -1 reverses its sign. If A1 is already negative, entering -1 returns a positive value.
The macro runs when B1 is edited. It does not recalculate B1 when A1 changes later, and it ignores edits to multiple cells at once.
In Excel, right-click the tab for the worksheet containing A1 and B1, then select View Code.
Paste this code into the worksheet's code window: Private Sub Worksheet_Change(ByVal Target As Range) If Target.CountLarge > 1 Then Exit Sub If Target.Address(False, False) <> "B1" Then Exit Sub On Error GoTo CleanUp If IsError(Target.Value) Or IsError(Me.Range("A1").Value) Then Exit Sub If Not IsNumeric(Target.Value) Or Not IsNumeric(Me.Range("A1").Value) Then Exit Sub If Target.Value = 1 Or Target.Value = -1 Then Application.EnableEvents = False Target.Value = Target.Value * Me.Range("A1").Value End If CleanUp: Application.EnableEvents = True End Sub
Choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm). Reopen the file if necessary and enable macros only if you trust the workbook.
Enter a number in A1, then type 1 in B1 and press Enter. Type -1 in B1 to check that the result has the opposite sign.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files and use standard formulas as you move your everyday spreadsheet work to WPS; the Excel VBA event macro described above requires compatible macro support.

Frequently Asked Questions
Where should I paste the Worksheet_Change code?
Right-click the worksheet tab in Excel and select View Code. Paste the event procedure into that worksheet's code module, not a standard module.
Why doesn't B1 update when I change A1?
The macro responds only to an edit in B1 and replaces the multiplier with a fixed value. Enter 1 or -1 in B1 again after changing A1.
What happens if A1 is negative?
Entering 1 in B1 returns the negative A1 value unchanged. Entering -1 reverses its sign, producing a positive value.
Why did my macro disappear after saving?
VBA code must be saved in a macro-enabled format. Use File > Save As and select Excel Macro-Enabled Workbook (*.xlsm), then enable macros when reopening a trusted file.
Will the macro change an entry other than 1 or -1?
No. The code checks B1 for those two values and leaves other entries unchanged.




