Use the following
Sheet code
Code:
Option Explicit
Sub amritraj()
With UserForm1
.wow.Value = True
With .Comb
.AddItem "addition"
.AddItem "subtraction"
End With
.Comb.Value = "subtraction"
.TextBox1.Value = 20
.TextBox2.Value = 30
.TextBox3.Value = 40
.Show
End With
Unload UserForm1
End Sub
Userform code
Code:
Option Explicit
Private Sub cancel_Click()
Hide
End Sub
Private Sub ok_Click()
Dim a As Variant, b As Variant, c As Variant
If TextBox1.Value = "" Then
MsgBox "a field is empty"
Exit Sub
End If
If TextBox2.Value = "" Then
MsgBox "b field is empty"
Exit Sub
End If
If TextBox3.Value = "" Then
MsgBox "c field is empty"
Exit Sub
End If
a = TextBox1.Value
b = TextBox2.Value
c = TextBox3.Value
If wow.Value = True Then
Select Case Comb.Value
Case "addition"
Call sum(a, b, c)
Case "subtraction"
Call minus(a, b, c)
End Select
End If
Hide
End Sub
Sub sum(a As Variant, b As Variant, c As Variant)
Cells(1, 1).Value = Application.WorksheetFunction.sum(a, b, c)
End Sub
Sub minus(a As Variant, b As Variant, c As Variant)
Cells(1, 1).Value = Application.WorksheetFunction.sum(a - b - c)
End Sub