Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-05-2018, 02:52 AM
phoenixmoto phoenixmoto is offline vba new Windows 7 64bit vba new Office 2007
Banned
vba new
 
Join Date: Jul 2018
Posts: 11
phoenixmoto is on a distinguished road
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 amritraj()
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

userform1 image is attached to this thread.
Attached Images
File Type: png userform1.png (239.6 KB, 18 views)
Reply With Quote
  #2  
Old 11-05-2018, 03:51 AM
gmayor's Avatar
gmayor gmayor is offline vba new Windows 10 vba new Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-05-2018, 07:09 PM
macropod's Avatar
macropod macropod is offline vba new Windows 7 64bit vba new Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: http://www.vbaexpress.com/forum/show...?64001-vba-new
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Other Forums: Access Forums

All times are GMT -7. The time now is 10:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft