0

I have a remaining budget value (txtETLAfterFunding), which is the roduct of (txtELTUnReqdDollars) - (txtBudget). If the txtETLAfterFunding is in the negative, I can use txtAdjustmentAmt to offset that negative budget.

i.e. txtETLAfterFunding = -$5,000, so I type in $5,000 in to the txtAdjustmentAmt and the txtETLAfterFunding amount is now $0. But say I mess up and want to type in $15,000 in txtAdjustmentAmt. Now the remaining budget balance adds that to the $0 from the last calc, where I want it to reset back to -$5,000 so that I can then add $15,000 to that and make the remaining budget at $10,000.

I know I need to put my txtELTAfterFunding as a global variable in order to have it reset, but I am lost on how to do that.

code:

Private Sub txtAdjustmentAmt_AfterUpdate()
    If optReduceReq = True Then
        txtELTAfterFunding.Value = CDbl(txtAdjustmentAmt.Value) + CDbl(txtELTAfterFunding.Value)
    End If
txtELTAfterFunding.Value = Format(txtELTAfterFunding, "$#,##.00")
End Sub
NidenK
  • 321
  • 1
  • 8
  • AFAIK It's strongly suggested against using global variables [read this](https://stackoverflow.com/a/485020/1521579). As an alternative you could store values in a cell, in the registry. If you decide to go the global variable path, [read this](https://www.mrexcel.com/board/threads/userforms-a-few-questions-on-variable-scope.456670/post-2255047) – Ricardo Diaz Jan 12 '21 at 19:29

1 Answers1

1

You could just set txtETLAfterFunding to be calculated as

txtETLAfterFunding = txtELTUnReqdDollars - txtBudget + txtAdjustmentAmt

You would then put the calculation into e.g. "Private Sub ReCalc", which you can call from the _AfterUpdate of the 3 textboxes.

As an aside, your Format code should probably read Format(txtELTAfterFunding, "$#,##0.00").

Morten
  • 148
  • 6