+ Reply to Thread
Results 1 to 10 of 10

Message box in excel

  1. #1
    Registered User
    Join Date
    10-03-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    76

    Message box in excel

    I made the following code. Basically if a cell value is 300000 then a message box appears saying "You have selected grants of £30000". Same thing for 500000. The issue I am having is, after the pop up message is appearing, I have to click on "ok" 2 times before it closes. I only want to press on ok once for it to close. How to fix this?

    Option Explicit

    Private Sub Worksheet_Calculate()

    Dim Rng1 As Range
    Dim Value As Double
    Dim Prompt As String
    Dim Title As String

    'Put the range you want to look at here
    Set Rng1 = Range("B7")

    'Put the target value here
    Value = 500000

    'Put the message (prompt) of the message box (pop up) here
    Prompt = "You have selected a grant of £500000"

    'Put the title of the message box (pop up) here
    Title = "Title"

    If Rng1.Value = Value Then
    MsgBox Prompt, vbInformation, Title
    End If





    'Put the range you want to look at here
    Set Rng1 = Range("B7")

    'Put the target value here
    Value = 300000

    'Put the message (prompt) of the message box (pop up) here
    Prompt = "You have selected a grant of £300000"

    'Put the title of the message box (pop up) here
    Title = "Title"

    If Rng1.Value = Value Then
    MsgBox Prompt, vbInformation, Title
    End If

    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Message box in excel

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Message box in excel

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  4. #4
    Registered User
    Join Date
    10-03-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    76

    Re: Message box in excel

    Thanks for that, but for some reason I still need to press 'Ok' twice for the pop up message to close

  5. #5
    Registered User
    Join Date
    10-03-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    76

    Message box in EXCEL

    I made a message box if the values 5000000 and 3000000 are entered in a cell. This is my code:

    Please Login or Register  to view this content.
    I am facing one problem. When the message box is appearing, I have to double click on OK to close the message. I only want to press ok once for the message to close. Not twice

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Message box in excel

    A Forum Moderator has asked you to take action ... you need to add code tags in your OP.

    Until you do that we cannot continue this dialogue.

  7. #7
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Message box in EXCEL

    Hi,

    I can't reproduce your problem... When testing you code, I only have to click once on the ok button or press once on Enter... whichis the normal behaviour of a message box... It this the whole code? or do you interact with other workbooks at the same time?

    Anyway, here's a suggestion to simplify your code. Note that it uses the _Change event so it will be triggered everytime a value is entered in cell B7 instead of everytime the sheet is "calculated".

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Registered User
    Join Date
    10-03-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    76

    Re: Message box in EXCEL

    Really? That's weird.

    Anyway I have used your code and for some reason now I only have to press once. Thanks for that

    Another question, can you have a look at what I posted here: http://www.excelforum.com/excel-prog...insurance.html

    And see if you can help me with that?

    Thanks!

  10. #10
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Message box in excel

    Threads are merged now.
    Don't create duplicated threads.

    As I pointed please read Forum Rules and don't ignore requests or expect to be locked.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding an input message to each cell to bring back corrsponding message
    By Nic31 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2014, 09:28 AM
  2. [SOLVED] How to pop up a warning message before any Excel automatic update link reminder message
    By billj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2013, 10:41 AM
  3. VBA code created in Excel 2003, not working in Excel 2010, Getting error message 400.
    By rajeshapril14 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-24-2012, 05:19 AM
  4. Extracting mail message(outlook) table in the message body
    By andywsw in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 10:14 PM
  5. need of pop up message dynamically using data validation input message method
    By vba_life in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2010, 09:03 AM
  6. Replace Excel Message w/Custom Message
    By Kevin R in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-18-2006, 11:15 AM
  7. [SOLVED] Intercept/replace standard 'cell protected' message with my own message?
    By KR in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-16-2006, 10:35 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1