shumidrives
New Member
- Joined
- Nov 9, 2016
- Messages
- 10
Private Sub TXTB1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'change TXTB1 to your textbox name
Call ADDUP
End Sub
Private Sub TXTB2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'change TXTB2 to your textbox name
Call ADDUP
End Sub
Private Sub TXTB3_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'change TXTB3 to your textbox name
Call ADDUP
End Sub
Private Sub TXTB4_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'change TXTB4 to your textbox name
Call ADDUP
End Sub
Private Sub TXTB5_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'change TXTB5 to your textbox name
Call ADDUP
End Sub
Private Sub TXTB6_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) 'change TXTB6 to your textbox name
Call ADDUP
End Sub
Private Sub TOTAL1_Change() 'change TOTAL1 to your textbox name
Call ADDUP
With Sheets("sheet1") ' change sheet1 to your sheet name
.Range("A1") = TOTAL1 ' change A1 to the range you want the total in the sheet
End With
End Sub
Sub ADDUP()
Dim num(1 To 6) As Integer
num(1) = TXTB1 'change TXTB1 to your textbox name
num(2) = TXTB2 'change TXTB2 to your textbox name
num(3) = TXTB3 'change TXTB3 to your textbox name
num(4) = TXTB4 'change TXTB4 to your textbox name
num(5) = TXTB5 'change TXTB5 to your textbox name
num(6) = TXTB6 'change TXTB6 to your textbox name
TOTAL1 = num(1) + num(2) + num(3) + num(4) + num(5) + num(6) 'change TOTAL1 to your textbox name
End Sub
Private Sub UserForm_Initialize()
TXTB1 = 0: TXTB2 = 0: TXTB3 = 0: TXTB4 = 0: TXTB5 = 0: TXTB6 = 0 'change TB1 to TB6 to your textbox names
TOTAL1.Enabled = False ' change TOTAL1 to you text box name
End Sub
Private Sub CMD1_Click() 'change to your command button name
Dim num(1 To 6) As Integer
num(1) = TXTB1 'change TXTB1 to your textbox name
num(2) = TXTB2 'change TXTB2 to your textbox name
num(3) = TXTB3 'change TXTB3 to your textbox name
num(4) = TXTB4 'change TXTB4 to your textbox name
num(5) = TXTB5 'change TXTB5 to your textbox name
num(6) = TXTB6 'change TXTB6 to your textbox name
TOTAL1 = num(1) + num(2) + num(3) + num(4) + num(5) + num(6) 'change TOTAL1 to your textbox
With Sheets("sheet1") ' change sheet1 to your sheet name
.Range("A1") = TOTAL1 ' change A1 to the range you want the total in the sheet and TOTAL1 to yout textbox name
End With
End Sub
Private Sub UserForm_Initialize()
TOTAL1.Enabled = False ' change TOTAL1 to you text box name
End Sub
Private Sub CommandButton1_Click()
Dim i As Long
Dim ans As Long
ans = 0
For i = 1 To 6
ans = Me.Controls("Textbox" & i).Value + ans
Next
TextBox7.Value = ans
End Sub
Private Sub Calculatebtn_click()On Error Resume Next
TextBox3 = (txtarrow1 + 0) + (txtarrow2 + 0) + (txtarrow3 + 0) + (txtarrow4 + 0) + (txtarrow5 + 0) + (txtarrow6 + 0)
TextBox4 = (txtarrow7 + 0) + (txtarrow8 + 0) + (txtarrow9 + 0) + (txtarrow10 + 0) + (txtarrow11 + 0) + (txtarrow12 + 0)
end sub
Use Val() to convert you textbox strings into numeric values.
For the X deal, what other roman numerals where you going to allow? That could get messy. I guess you can Replace() after a lost focus or KeyDown, KeyUp, or KeyPress event for each textbox control.
end1 = (IIf(Me.txtarrow1 = "x", 10, Me.txtarrow1) + 0)
Private Sub Calculatebtn_click()
SumTBs TextBox3, 1, 6
SumTBs TextBox4, 7, 12
End Sub
Private Sub SumTBs(tb As msforms.TextBox, iFrom%, iTo%, _
Optional tbPrefix$ = "txtarrow")
Dim d#, i%, tbs As msforms.TextBox
For i = iFrom To iTo
Set tbs = Controls(tbPrefix & i)
d = d + Val(IIf(Len(tbs.Value) = 1, _
Replace(LCase(tbs.Value), "x", "10"), tbs.Value))
Next i
tb = d
End Sub