ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   calculating textboxes (https://www.excelbanter.com/excel-programming/366958-calculating-textboxes.html)

enyaw

calculating textboxes
 
I have four textboxes. 3 of them are multiplied by each other to get the
answer in the fourth box. Sometimes there is not information for the first
three boxes so the fourth textbox must be inputted manually. I need to able
to automatically calculate when there is information and manually input when
there is none. I need some coding to be able to this. I also need to
disable the total box when calculating manually but enable it when entering
manually. Can anyone help?

SyrNO

calculating textboxes
 
I don't know if this is the most efficient way to do this, but it works. Try
the following code for the Exit Event for each of the 3 text boxes,

Private Sub txt1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim v1 As Double
Dim v2 As Double
Dim v3 As Double

If txt1.Value = "" And txt2.Value = "" And txt3.Value = "" Then
txt4.Enabled = True
Else:
txt4.Enabled = False
If txt1.Value = "" Then
v1 = 1
Else:
v1 = txt1.Value
End If
If txt2.Value = "" Then
v2 = 1
Else:
v2 = txt2.Value
End If
If txt3.Value = "" Then
v3 = 1
Else:
v3 = txt3.Value
End If
txt4.Value = v1 * v2 * v3
End If

End Sub

"enyaw" wrote:

I have four textboxes. 3 of them are multiplied by each other to get the
answer in the fourth box. Sometimes there is not information for the first
three boxes so the fourth textbox must be inputted manually. I need to able
to automatically calculate when there is information and manually input when
there is none. I need some coding to be able to this. I also need to
disable the total box when calculating manually but enable it when entering
manually. Can anyone help?



All times are GMT +1. The time now is 03:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com