Help needing two cells equal a constant value.

jgui

New Member
Joined
Aug 8, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
This formula (macro?) will live in cells c16 and c17. What I am attempting to do is always have two cells total a specific value of 62. For example, when I subtract from c16, it will add that number to c17 so that the two values combined always equal 62, and then vice versa. If I add to c16, it will subtract that amount from c17. Is this possible?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Put this behind your sheet module

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 With Target
   If .Count > 1 Then Exit Sub
   Application.EnableEvents = False
   If Not Intersect(.Offset, Range("C16:C17")) Is Nothing Then .Offset(IIf(.Row = 16, 1, -1)) = 62 - .Value
   Application.EnableEvents = True
 End With
End Sub
 
Upvote 0
Put this behind your sheet module

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 With Target
   If .Count > 1 Then Exit Sub
   Application.EnableEvents = False
   If Not Intersect(.Offset, Range("C16:C17")) Is Nothing Then .Offset(IIf(.Row = 16, 1, -1)) = 62 - .Value
   Application.EnableEvents = True
 End With
End Sub
Thank you so much for the help!
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,853
Members
449,194
Latest member
HellScout

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