Consulting

Results 1 to 3 of 3

Thread: Msg Box pops up many times

  1. #1
    VBAX Regular
    Joined
    Jul 2011
    Posts
    6
    Location

    Msg Box pops up many times

    Hi!

    I have a simple UFD in VBA for Excel. This user defined function has 6 parameters. If the value of parameter b is greater than parameter c a msg-box opens.

    At that special case when all parameters are in and I want to change an input I get more than one times the same msg box. I get this boxes before I confirm the entries with return and also when I reopen the function button.

    Also, when I click the scroll bar on the right side of the function window (parameter functions), the program gets crazy and the msg box opens more then 50 times.

    Can I avoid the plural opening of the same msg-box?


    This is the VBA Code

    [vba]Function Testpopup(a As String, b As Double, c As Double, d As Double, _
    e As Double, f As Double) As Variant
    If b > c Then MsgBox ("b has a value greater than c")
    Testpopup = (b + c + d + e + f) & a
    End Function
    [/vba]
    I use Excel 2003 and 2007.

    Thanks for an answer.

    Gentile
    Last edited by Aussiebear; 08-01-2011 at 02:28 PM. Reason: Added vba tags to code

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Do not use a MsgBox in a UDF. Everytime calculation occurs, it will execute. Use Debug.Print if you really need to see what happened.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    I agree with Ken, but a 'sort of' OK might be to return the error message

    [VBA]
    Function Testpopup(a As String, b As Double, c As Double, d As Double, _
    e As Double, f As Double) As Variant

    If b > c Then
    TestPopup = "b has a value greater than c"

    else
    Testpopup = (b + c + d + e + f) & a
    endif

    End Function
    [/VBA]

    Paul

Posting Permissions

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