ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I? (https://www.excelbanter.com/excel-programming/361482-how-do-i.html)

Greg[_27_]

How do I?
 
How do I add the total of two tetboxes together in vb code. I need the total
displayed in a textbox called "total"
the textboxes are "f5" & "f6"

Thanks

Greg



Barry-Jon

How do I?
 
Use the chaneg events for the two "input" boxes to call a proc that
will update the total box. You will also need to handle errors and
non-numeric input. The basics are below. Please let me know if this
is what you were looking for.

Private Sub f5_Change()

RecalcTotal

End Sub

Private Sub f6_Change()

RecalcTotal

End Sub

Private Sub RecalcTotal()

Dim dblF5 As Double
Dim dblF6 As Double

If IsNumeric(Me.f5.Value) And IsNumeric(Me.f6.Value) Then

dblF5 = CDbl(Me.f5.Value)
dblF6 = CDbl(Me.f6.Value)

Me.total.Value = dblF5 + dblF6

Else

'handle non numeric input here

End If

End Sub



All times are GMT +1. The time now is 12:53 PM.

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