Consulting

Results 1 to 3 of 3

Thread: vba new

  1. #1
    Banned VBAX Regular
    Joined
    Jul 2018
    Posts
    9
    Location

    Question vba new

    Here module1 code is initialised when i run Amritraj() macro and then userform1 is showed
    when i click ok command button nothing happens. actually it should have run sum macro and addition should have executedmodule1 code


    Sub phoenixmoto()
    Call initialise
    UserForm1.Show
    End Sub


    Sub initialise()
    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
    End With
    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


    userform1 code

    Private Sub cancel_Click()
    Unload UserForm1
    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
    End Sub

    here is screenshot of userform1
    userform1.jpg

  2. #2
    This Excel question was asked and answered at http://www.msofficeforums.com/word/4...w-newpost.html
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    phoenixmoto: Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq...._new_faq_item3
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •