Adjacent cells in two columns always sum to a number

Cyclops755

New Member
Joined
Jul 26, 2011
Messages
31
This'll be my first post up here, so here goes:

I have two columns of data, both of which contain percentage data. I'd like to have a way to force each row to always sum to 100, regardless of which column data is entered into, and that will auto-"rebalance" if the data in either of the columns is changed.
Any thoughts?

Thanks!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Welcome to the Board!

That can be done with some VBA, specifically an Event Procedure which automatically fires whenever a value in your desired range is manually updated.

The following code is set to work on the first two columns, but you can change as needed. To insert this code where it needs to go, right-click on the Sheet name tab, select View Code, and paste this code in the resulting window:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
'   Limit to only work on columns 1 or 2
    If Target.Column = 1 Or Target.Column = 2 Then
        Application.EnableEvents = False
        If Target.Column = 1 Then Target.Offset(0, 1).Value = 1 - Target.Value
        If Target.Column = 2 Then Target.Offset(0, -1).Value = 1 - Target.Value
        Application.EnableEvents = True
    End If
    
End Sub
Then just start entering values in columns A and B and see it work!
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

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