Photomommie
New Member
- Joined
- Feb 10, 2019
- Messages
- 2
I have 20 textboxes in my userform that need to be added as a "Subtotal"
I have it working now, but it is very clunky and I thought there might be a better way of handling this.
Here is an example of the code:
Etc.... for 20 textboxes.
Is there a cleaner way to do this???
I have it working now, but it is very clunky and I thought there might be a better way of handling this.
Here is an example of the code:
Code:
Private Sub tbxPrice1_Change()
Dim tbxPriceSum As Double
If Me.tbxPrice1.value = Empty Then Me.tbxPrice1.value = "$0.00"
If Me.tbxPrice2.value = Empty Then Me.tbxPrice2.value = "$0.00"
If Me.tbxPrice3.value = Empty Then Me.tbxPrice3.value = "$0.00"
If Me.tbxPrice4.value = Empty Then Me.tbxPrice4.value = "$0.00"
If Me.tbxPrice5.value = Empty Then Me.tbxPrice5.value = "$0.00"
If Me.tbxPrice6.value = Empty Then Me.tbxPrice6.value = "$0.00"
If Me.tbxPrice7.value = Empty Then Me.tbxPrice7.value = "$0.00"
If Me.tbxPrice8.value = Empty Then Me.tbxPrice8.value = "$0.00"
If Me.tbxPrice9.value = Empty Then Me.tbxPrice9.value = "$0.00"
If Me.tbxPrice10.value = Empty Then Me.tbxPrice10.value = "$0.00"
If Me.tbxPrice11.value = Empty Then Me.tbxPrice11.value = "$0.00"
If Me.tbxPrice12.value = Empty Then Me.tbxPrice12.value = "$0.00"
If Me.tbxPrice13.value = Empty Then Me.tbxPrice13.value = "$0.00"
If Me.tbxPrice14.value = Empty Then Me.tbxPrice14.value = "$0.00"
If Me.tbxPrice15.value = Empty Then Me.tbxPrice15.value = "$0.00"
If Me.tbxPrice16.value = Empty Then Me.tbxPrice16.value = "$0.00"
If Me.tbxPrice17.value = Empty Then Me.tbxPrice17.value = "$0.00"
If Me.tbxPrice18.value = Empty Then Me.tbxPrice18.value = "$0.00"
If Me.tbxPrice19.value = Empty Then Me.tbxPrice19.value = "$0.00"
If Me.tbxPrice20.value = Empty Then Me.tbxPrice20.value = "$0.00"
Me.tbxPriceSum.value = WorksheetFunction.Sum(Me.tbxPrice1.value, Me.tbxPrice2.value, Me.tbxPrice3.value, Me.tbxPrice4.value, Me.tbxPrice5.value, Me.tbxPrice6.value, Me.tbxPrice7.value, Me.tbxPrice8.value, Me.tbxPrice9.value, Me.tbxPrice10.value, Me.tbxPrice11.value, Me.tbxPrice12.value, Me.tbxPrice13.value, Me.tbxPrice14.value, Me.tbxPrice15.value, Me.tbxPrice16.value, Me.tbxPrice17.value, Me.tbxPrice18.value, Me.tbxPrice19.value, Me.tbxPrice20.value)
Me.tbxPriceSum.value = Format(Me.tbxPriceSum.value, "$###,##0.00")
End Sub
Private Sub tbxPrice2_Change()
Dim tbxPriceSum As Double
If Me.tbxPrice1.value = Empty Then Me.tbxPrice1.value = "$0.00"
If Me.tbxPrice2.value = Empty Then Me.tbxPrice2.value = "$0.00"
If Me.tbxPrice3.value = Empty Then Me.tbxPrice3.value = "$0.00"
If Me.tbxPrice4.value = Empty Then Me.tbxPrice4.value = "$0.00"
If Me.tbxPrice5.value = Empty Then Me.tbxPrice5.value = "$0.00"
If Me.tbxPrice6.value = Empty Then Me.tbxPrice6.value = "$0.00"
If Me.tbxPrice7.value = Empty Then Me.tbxPrice7.value = "$0.00"
If Me.tbxPrice8.value = Empty Then Me.tbxPrice8.value = "$0.00"
If Me.tbxPrice9.value = Empty Then Me.tbxPrice9.value = "$0.00"
If Me.tbxPrice10.value = Empty Then Me.tbxPrice10.value = "$0.00"
If Me.tbxPrice11.value = Empty Then Me.tbxPrice11.value = "$0.00"
If Me.tbxPrice12.value = Empty Then Me.tbxPrice12.value = "$0.00"
If Me.tbxPrice13.value = Empty Then Me.tbxPrice13.value = "$0.00"
If Me.tbxPrice14.value = Empty Then Me.tbxPrice14.value = "$0.00"
If Me.tbxPrice15.value = Empty Then Me.tbxPrice15.value = "$0.00"
If Me.tbxPrice16.value = Empty Then Me.tbxPrice16.value = "$0.00"
If Me.tbxPrice17.value = Empty Then Me.tbxPrice17.value = "$0.00"
If Me.tbxPrice18.value = Empty Then Me.tbxPrice18.value = "$0.00"
If Me.tbxPrice19.value = Empty Then Me.tbxPrice19.value = "$0.00"
If Me.tbxPrice20.value = Empty Then Me.tbxPrice20.value = "$0.00"
Me.tbxPriceSum.value = WorksheetFunction.Sum(Me.tbxPrice1.value, Me.tbxPrice2.value, Me.tbxPrice3.value, Me.tbxPrice4.value, Me.tbxPrice5.value, Me.tbxPrice6.value, Me.tbxPrice7.value, Me.tbxPrice8.value, Me.tbxPrice9.value, Me.tbxPrice10.value, Me.tbxPrice11.value, Me.tbxPrice12.value, Me.tbxPrice13.value, Me.tbxPrice14.value, Me.tbxPrice15.value, Me.tbxPrice16.value, Me.tbxPrice17.value, Me.tbxPrice18.value, Me.tbxPrice19.value, Me.tbxPrice20.value)
Me.tbxPriceSum.value = Format(Me.tbxPriceSum.value, "$###,##0.00")
End Sub
Etc.... for 20 textboxes.
Is there a cleaner way to do this???