Add to one column, subtract to another.

BradMcLeod

New Member
Joined
Jun 8, 2015
Messages
40
I feel this may have to be a macro, because of the scale and the way I'm using it.
I want J3 and higher (J4, J5 etc) to subtract 1 from itself everytime G3 and higher change. In the same line.
If G4 changes, then J4 subtracts 1 from itself
If G5 changes, then J5 subtracts 1 from itself.

Column G will only ever go up. As it is ALREADY in a formula of auto sum of B, C and D. This will have to be a macro, I believe, because the starting number for J will be fluid, and have to be input and periodically changed, manually.
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,871
Office Version
  1. 365
Platform
  1. Windows
Column G will only ever go up. As it is ALREADY in a formula of auto sum of B, C and D.
Is column G just summing up the values of B, C, and D in the same row?
Are the values in B, C, and D manually entered?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,871
Office Version
  1. 365
Platform
  1. Windows
Right-click on the sheet tab name at the bottom of the screen, select View Code, and paste this code in the VB Editor window that pops up.
This should do what you want automatically, anytime a a value is updated in columns B, C, or D, starting on row 3, the value in column J of that row will be decreased by one.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng1 As Range
    Dim rng2 As Range
    Dim cell As Range
    
'   Set range to watch for changes
    Set rng1 = Range("B3:D" & Rows.Count)
    
'   See if any watched cells change
    Set rng2 = Intersect(rng1, Target)
    
'   Exit if no cells in watched range updated
    If rng2 Is Nothing Then Exit Sub
    
'   Loop through changed cells in watched ranges
    For Each cell In rng2
'       Remove one from column J in that row
        Cells(cell.Row, "J") = Cells(cell.Row, "J") - 1
    Next cell

End Sub
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,871
Office Version
  1. 365
Platform
  1. Windows
You are welcome!
 

Watch MrExcel Video

Forum statistics

Threads
1,114,236
Messages
5,546,656
Members
410,753
Latest member
Ian R
Top