Formula or code

noelmus

Board Regular
Joined
Dec 30, 2018
Messages
105
Hi,
Currently in worksheet (CHIT) I have E22=E20-E21 and the same H22=H20-H21, so I'm going to focus on E22=E20-E21.
I need that I can also update E22 so that E20=E21+E22. So in few words, I can update E20 to get an answer in E22 or update E22 to get an answer in E20. Just to remind you that even for H20,H21 and H22, I need the same thing.
I don't know if its possible to work with a formula or code. In case it works with a code I already have these:


In workbook:


Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim ws As Worksheet


Set ws = Worksheets("CHIT")
If Sh.Name = ws.Name Then
ws.Range("C11") = Application.UserName
End If


Set ws = Nothing
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("CHIT").Range("J9,J12,C14,E28,E29").Interior.ColorIndex = 6
End Sub


In worksheet:


Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("J9,J12,C14,E28,E29")) Is Nothing Then
If Target.Count > 1 Then Exit Sub
If Target.Value = "" Then
Target.Interior.ColorIndex = 6
Else
Target.Interior.ColorIndex = xlNone
End If
End If
End Sub

Thanks in advance
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi,

You will need an Even macro ...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("E20,E22,H20,H22")) Is Nothing Then Exit Sub
Application.EnableEvents = False
    If Target.Row = 20 Then
        Target.Offset(2, 0) = Target - Target.Offset(1, 0)
    Else
        Target.Offset(-2, 0) = Target + Target.Offset(-1, 0)
    End If
Application.EnableEvents = True
End Sub

Hope this will help
 
Upvote 0
Glad the macro is helping you out ...

006 is Before tax ..

So if you were to add 16.66 % Tax ... you will probably reach 7 ... :)
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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