How to write code for circular referance formula

jovie

Board Regular
Joined
Nov 13, 2015
Messages
68
I would write code for few columns that perform that
Cell 1 -Cell 2 +Cell 3 = Cell3(new)
However I can only write for one cell, cant perform in one column, and if I never clear the value in cell 1 or cell 2, it will still work like the formula
I want to perform like
if I never change the value in cell1 or cell2, then the value for the cell performed in the formula will be 0
just like said I enter the value in cell 1 is 2 and cell 2 is 1 and original value in cell 3 is 2
so the result is 2-1+2=3
but next time I change the value in cell 1 to 3 and I did not clear the cell 2 , I want it to performed like
3-0+3=6
instead of .
3-1+3=5

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
 If Not (Intersect(Target, Range("A,B")) Is Nothing) Then
 Range("C").Value = Range("A").Value - Range("B").Value + Range("C").Value
 
 End If
 End Sub
 
Last edited by a moderator:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
this piece of code was written for me but does something similar to what you trying to do so might help

it calculates the all three columns based on input made to any one of them

it is a sheet code fired on any sheet change

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If (Target.Row >= 5 And Target.Row <= 25) Then
    If (Not Intersect(Target, Columns("B")) Is Nothing) Then
        Target.Offset(0, 2) = Target * 52
        Target.Offset(0, 1) = Target.Offset(0, 2) / 12
    ElseIf (Not Intersect(Target, Columns("C")) Is Nothing) Then
        Target.Offset(0, 1) = Target * 12
        Target.Offset(0, -1) = Target.Offset(0, 1) / 52
    ElseIf (Not Intersect(Target, Columns("D")) Is Nothing) Then
        Target.Offset(0, -1) = Target / 12
        Target.Offset(0, -2) = Target / 52
    End If
End If
Application.EnableEvents = True
End Sub


my VBA not quite good enough to help with customised solution for your need sorry
 
Upvote 0
It is okay and I write code already however it is not working so I am really very confused
 
Upvote 0
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Application.EnableEvents = False
n = Range("a65535").End(xlUp).Row
For i = 1 To n
If Not (Intersect(Target, Range("G" & i)) Is Nothing) Then
Range("J" & i).Value = Range("G" & i).Value + Range("J" & i).Value

End If
If Not (Intersect(Target, Range("H" & i)) Is Nothing) Then
Range("J" & i).Value = Range("J" & i).Value - Range("H" & i).Value
End If
Next
Application.EnableEvents = True

End Sub
I write this code, it is working in other workbooks but it is no use at all in my workbooks. I am really very confused
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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