Arie Bos
Board Regular
- Joined
- Mar 25, 2016
- Messages
- 224
- Office Version
- 365
- Platform
- Windows
Hello excel friends,
I have 12 textboxes asking for a simple integer. there is a label following, where the values of each textbox is added up.
This is all very simple, but the code below does look a bit primitive to me to have to put the _change of each textbox in a separate subroutine. I wonder if this could not be written in a much more elegant way?
I have 12 textboxes asking for a simple integer. there is a label following, where the values of each textbox is added up.
This is all very simple, but the code below does look a bit primitive to me to have to put the _change of each textbox in a separate subroutine. I wonder if this could not be written in a much more elegant way?
VBA Code:
Sub calctotal()
Dim TotalCostsforInstallation As Long
TotalCostsforInstallation = _
Val(Amount01.Value) * Val(UnitCost01.Value) + _
Val(Amount02.Value) * Val(UnitCost02.Value) + _
Val(Amount03.Value) * Val(UnitCost03.Value) + _
Val(Amount04.Value) * Val(UnitCost04.Value) + _
Val(Amount05.Value) * Val(UnitCost05.Value) + _
Val(Amount06.Value) * Val(UnitCost06.Value) + _
Val(Amount07.Value) * Val(UnitCost07.Value) + _
Val(Amount08.Value) * Val(UnitCost08.Value) + _
Val(Amount09.Value) * Val(UnitCost09.Value) + _
Val(Amount10.Value) * Val(UnitCost10.Value) + _
Val(Amount11.Value) * Val(UnitCost11.Value) + _
Val(Amount12.Value) * Val(UnitCost12.Value)
Debug.Print "TotalCostsforInstallation = " & TotalCostsforInstallation
LblTotalEstInvestment.Caption = Format(TotalCostsforInstallation, "#,##")
End Sub
Private Sub Amount01_Change()
calctotal
End Sub
Private Sub Amount02_Change()
calctotal
End Sub
Private Sub Amount03_Change()
calctotal
End Sub
Private Sub Amount04_Change()
calctotal
End Sub
Private Sub Amount05_Change()
calctotal
End Sub
Private Sub Amount06_Change()
calctotal
End Sub
Private Sub Amount07_Change()
calctotal
End Sub
Private Sub Amount08_Change()
calctotal
End Sub
Private Sub Amount09_Change()
calctotal
End Sub
Private Sub Amount10_Change()
calctotal
End Sub
Private Sub Amount11_Change()
calctotal
End Sub
Private Sub Amount12_Change()
calctotal
End Sub
Private Sub UnitCost01_change()
calctotal
End Sub
Private Sub UnitCost02_change()
calctotal
End Sub
Private Sub UnitCost03_change()
calctotal
End Sub
Private Sub UnitCost04_change()
calctotal
End Sub
Private Sub UnitCost05_change()
calctotal
End Sub
Private Sub UnitCost06_change()
calctotal
End Sub
Private Sub UnitCost07_change()
calctotal
End Sub
Private Sub UnitCost08_change()
calctotal
End Sub
Private Sub UnitCost09_change()
calctotal
End Sub
Private Sub UnitCost10_change()
calctotal
End Sub
Private Sub UnitCost11_change()
calctotal
End Sub
Private Sub UnitCost12_change()
calctotal
End Sub