VBA & Macro Problems

Make Excel Cell B1 Return A1 or Its Negative with VBA

Maira MehtabMaira Mehtab Dec 2, 2026 868 views

Question details

Replace an entry of 1 or -1 in Excel cell B1 with the corresponding value calculated from A1.

Make Excel Cell B1 Return A1 or Its Negative with VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the sheet's code module

In Excel, right-click the tab for the worksheet containing A1 and B1, then select View Code.

2
Add the event macro

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

3
Save as a macro-enabled workbook

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.

4
Test B1

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.

Use a Worksheet_Change macro in the worksheet module
B1 stores the result: The macro replaces the typed multiplier with a value, not a formula. To apply a new A1 value, enter 1 or -1 in B1 again.
Free Microsoft Office alternative

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.

Use spreadsheet formulas to calculate A1 or its negative in a separate cell.Open and edit compatible Microsoft Excel XLSX files.Navigate spreadsheets with a familiar, easy-to-use interface.Use a free, lightweight office suite for everyday documents.
microsoft office alternative - wps office

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.