Results 1 to 11 of 11
  1. #1
    Lounger
    Join Date
    Jul 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Button with result in messagebox (Excel XP)

    Can anyone tell me how to insert a command-button in a sheet, wich calculates a formula and displays the result in a messagebox?

    Tnx

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Button with result in messagebox (Excel XP)

    You will have to write some VBA code for this. There are two types of command buttons you can put on a worksheet: from the "Forms" (Formulieren) toolbar and from the "Control Toolbox" (Werkset Besturingselementen) toolbar.
    If you add a command button from the Forms toolbar, a dialog to assign a macro will automatically come up. Modify the proposed name if you like, then click "New". Post back with details if you would like to have help writing the macro.

  3. #3
    Lounger
    Join Date
    Jul 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button with result in messagebox (Excel XP)

    Hans,

    I have succesfully added a command button into my sheet. When i click the button I want to execute a formule. Then i want the result of that formula displayed in a messagebox. The messagebox only has to have an OK button to close it.

    TNX

    Gerben

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Button with result in messagebox (Excel XP)

    Gerben,

    You'll have to provide some details of what you want to do - it is not clear what you mean by "execute a formule". The second part is easy: say that the result you want to display is in a variable strResult. You can use

    MsgBox strResult

    to display it in a message box with only an OK button.

  5. #5
    Lounger
    Join Date
    Jul 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button with result in messagebox (Excel XP)

    Hans,

    The formula is:
    =L20*(40%+M21)+L23

    The result must be displayed in a message box

    TNX
    Gerben

  6. #6
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Button with result in messagebox (Excel XP)

    this line in a macro will work:

    <pre>msgbox("Result is: "& range("L20").value*(.40+range("M21").value)+range( "L23").value)</pre>


    Add more verbiage is desired.

    Steve

  7. #7
    Lounger
    Join Date
    Jul 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button with result in messagebox (Excel XP)

    It's not working for 100%. Maybe the thing you must know is that:
    L20=Currency
    M21=Percentage
    L23=Currency
    Result must be displayed as currency

    Gerben

    P.S. Can you give me a good help/knowledge base so I can learn this myself?

  8. #8
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Button with result in messagebox (Excel XP)

    What do you mean "not working" for 100%? 100% instead of 40%: Use 1 (=100%) instead of the 0.4 (=40%) that I used.

    msgbox("Result is: "& range("L20").value*(0.4+range("M21").value)+range( "L23").value)

    Use this to format as currency:
    msgbox("Result is: "& Format(range("L20").value*(0.4+range("M21").value) +range("L23").value,"$0.00"))

    The format of the individual cells is immaterial

    Steve

  9. #9
    Lounger
    Join Date
    Jul 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button with result in messagebox (Excel XP)

    It's not working for 100%, i mean that that code is not working.

    I get the message "Types do not match"

  10. #10
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Button with result in messagebox (Excel XP)

    What is your line of code?
    and what is in the cells referenced?

    It sounds like at least one of them is NOT a number.

    Steve

  11. #11
    Lounger
    Join Date
    Jul 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button with result in messagebox (Excel XP)

    sorry,

    one of the cells weren't filled in yet. The code is working !!
    Thank you very much...

    Gerben

Posting Permissions

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