View Single Post
 
Old 04-19-2022, 05:44 AM
Formd Formd is offline Windows 7 32bit Office 2007
Advanced Beginner
 
Join Date: Feb 2015
Location: TX
Posts: 49
Formd is on a distinguished road
Default

I have another issue related to this same problem.

I have a second and third totals to add to the same table.
So I used the following.

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



Private Sub tbsubamt1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If FormatCell(tbsubamt1) = True Then SuperAdd
End Sub
Private Sub tbsubamt2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If FormatCell(tbsubamt2) = True Then SuperAdd
End Sub
Private Sub tbsubamt3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If FormatCell(tbsubamt3) = True Then SuperAdd
End Sub
Private Sub tbsubamt4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If FormatCell(tbsubamt4) = True Then SuperAdd
End Sub
Private Sub SuperAdd()
Dim aCtl As Control, dblTotal As Double
For Each aCtl In Me.Controls
If aCtl.Tag = "Subit" Then
If IsNumeric(aCtl) Then dblTotal = dblTotal + aCtl
End If
Next aCtl
Me.tbsubtot = Format(dblTotal, "$#,##0.00;($#,##0.00);0")
End Sub
Private Sub tbtotalsub_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If FormatCell(tbtotalsub) = True Then SuperAd
End Sub
Private Sub tbsubtot_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If FormatCell(tbsubtot) = True Then SuperAd
End Sub
Private Sub SuperAd()
Dim aCtl As Control, dblTotal As Double
For Each aCtl In Me.Controls
If aCtl.Tag = "grandt" Then
If IsNumeric(aCtl) Then dblTotal = dblTotal + aCtl
End If
Next aCtl
Me.tbgrantot = Format(dblTotal, "$#,##0.00;($#,##0.00);0")
End Sub



Everything works except the grand total "tbgrantot".
What I am trying to do is sum tbgtotal + tbsubtot = tbgrantot
so I tagged tbgtotal and tbsubtot but nothing shows up in tbgrantot
Help..
Reply With Quote