View Single Post
 
Old 04-10-2022, 09:41 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,161
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This works for me. I used the Tag property set to "AddMe" on any controls I want to be in the total.
Code:
Private Sub tbamt1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If FormatCell(tbamt1) = True Then SuperAdder
End Sub

Private Sub tbamt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If FormatCell(tbamt2) = True Then SuperAdder
End Sub

Private Sub tbamt3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If FormatCell(tbamt3) = True Then SuperAdder
End Sub

Private Sub tbamt4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If FormatCell(tbamt4) = True Then SuperAdder
End Sub

Private Sub tbamt5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If FormatCell(tbamt5) = True Then SuperAdder
End Sub

Private Sub tbamt6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If FormatCell(tbamt6) = True Then SuperAdder
End Sub

Private Function FormatCell(aCtl As Control) As Boolean
  If IsNumeric(aCtl.Value) Then
    aCtl.Value = Format(aCtl.Value, "#,##0.00;(#,##0.00);0")
    FormatCell = True
  ElseIf aCtl = "" Then
    aCtl = 0
    FormatCell = True
  End If
End Function

Private Sub SuperAdder()
  Dim aCtl As Control, dblTotal As Double
  For Each aCtl In Me.Controls
    If aCtl.Tag = "AddMe" Then
      If IsNumeric(aCtl) Then dblTotal = dblTotal + aCtl
    End If
  Next aCtl
  Me.tbgtotal = Format(dblTotal, "#,##0.00;(#,##0.00);0")
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote