Home > Mobile >  formula output and user input on same cell
formula output and user input on same cell

Time:12-01

I am trying to put formula output and user input on same cell

Private Sub Worksheet_Change(ByVal target As Range)
Application.EnableEvents = False
If Intersect(target, Range("G1103:G1104")) Is Nothing Then          
End If
ActiveSheet.Range("G1105").Formula = "=if(G1104="""","""",(((G1104-G1103)/G1103)*100))"

Application.EnableEvents = True
Exit sub

but this is not working and i not able to do manual entry on cell G1105. I want to leave cell G1103 and G1104 for user input and calculate G1105 but user should be able to directly put number in cell G1105 without changing the formula and it should do calculation next time user put value in cell G1103 and G1104.

I cannot do exit sub after if nothing then because i have other code that needs to run on same event worksheet_change.

CodePudding user response:

This will replace whatever is in G1105 with your Formula only when G1103 or G1104 are changed by the user.

Private Sub Worksheet_Change(ByVal target As Range)
    Application.EnableEvents = False
    If Not Intersect(target, Me.Range("G1103:G1104")) Is Nothing Then
        Me.Range("G1105").Formula = "=if(G1104="""","""",(((G1104-G1103)/G1103)*100))"
    End If

    ' rest of your code here

    Application.EnableEvents = True
Exit sub
  • Related