ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   sum function in a userfrom (https://www.excelbanter.com/excel-programming/320065-sum-function-userfrom.html)

niteman[_2_]

sum function in a userfrom
 
Hello everybody, I new at this and I'm trying to make a userfrom that well
sum several txtboxes with the total at the bottom of the form, the
information from the txtboxes, is use to update a worksheet, kind of like
forcastsales for one day's work from 11AM -11PM how can I do it before
updating the worksheet getting the total of the day.
eny help well be in advance apreciated

K Dales[_2_]

sum function in a userfrom
 
Here is some sample code (with a bit of data validation included) that could
be modified - this code would go in your Userform Code pane. I used 4
textboxes called T1, T2, T3 and TSUM - TSUM could (should) have Enabled =
False. I put the result in cell B3 but you can modify that to whatever you
need it to be, and of course you could store the individual textbox values in
any other cells as you wish.

Public T1Val As String
Public T2Val As String
Public T3Val As String

Private Sub T1_Change()

If Not (IsNumeric(T1) Or IsNull(T1) Or (T1 = "")) Then
Beep
T1 = T1Val
Else
T1Val = T1
TSUM.Text = Val(T1) + Val(T2) + Val(T3)
Range("B3") = Val(TSUM)
End If

End Sub

Private Sub T2_Change()

If Not (IsNumeric(T2) Or IsNull(T2) Or (T2 = "")) Then
Beep
T2 = T2Val
Else
T2Val = T2
TSUM.Text = Val(T1) + Val(T2) + Val(T3)
Range("B3") = Val(TSUM)
End If

End Sub

Private Sub T3_Change()

If Not (IsNumeric(T3) Or IsNull(T3) Or (T3 = "")) Then
Beep
T3 = T3Val
Else
T3Val = T3
TSUM.Text = Val(T1) + Val(T2) + Val(T3)
Range("B3") = Val(TSUM)
End If

End Sub



"niteman" wrote:

Hello everybody, I new at this and I'm trying to make a userfrom that well
sum several txtboxes with the total at the bottom of the form, the
information from the txtboxes, is use to update a worksheet, kind of like
forcastsales for one day's work from 11AM -11PM how can I do it before
updating the worksheet getting the total of the day.
eny help well be in advance apreciated


Bob Phillips[_6_]

sum function in a userfrom
 
Have a command button that does it

e.g.

TextBox4.Text = Format(CDbl(Textbox1.Text) + _
CDbl(Textbox2.Text) + _
CDbl(Textbox3.Text),"#,##0.00")

--

HTH

RP
(remove nothere from the email address if mailing direct)


"niteman" wrote in message
...
Hello everybody, I new at this and I'm trying to make a userfrom that well
sum several txtboxes with the total at the bottom of the form, the
information from the txtboxes, is use to update a worksheet, kind of like
forcastsales for one day's work from 11AM -11PM how can I do it before
updating the worksheet getting the total of the day.
eny help well be in advance apreciated





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

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