Enter a value in one cell and subtract from another that has a value already in it without formula

lurch7892

New Member
Joined
Jun 7, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I currently has a range of cells B4:B801. There are no formulas in these cells, just values. I need to input a number in the corresponding cell in column A, hit ENTER, and have this number subtracted from the cell in column B, and display the result.

Example: B4 contains the number 28. I types in the number 5 in cell A4 and hits ENTER. B4 should change to number 23.

Can someone help with this? I'm sure it has to be done in code.


Thanks
Lurch7892
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Welcome to the Board!

Right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this code in the resulting VB Editor window that pops up.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
    
    Set rng = Intersect(Target, Range("A:A"))
    
    If rng Is Nothing Then Exit Sub
    
    Application.EnableEvents = False
    
    For Each cell In rng
        cell.Offset(0, 1).Value = cell.Offset(0, 1).Value - cell.Value
    Next cell
    
    Application.EnableEvents = True
    
End Sub
So whenever you enter a value in column A, it will automatically subtract it from column B.
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,804
Members
449,337
Latest member
BBV123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top