+ Reply to Thread
Results 1 to 2 of 2

MsgBox working but shows second time after clicking OK

Hybrid View

Stella9 MsgBox working but shows... 02-28-2013, 11:28 PM
djbomaha Re: MsgBox working but shows... 02-28-2013, 11:53 PM
  1. #1
    Registered User
    Join Date
    01-03-2013
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    1

    Question MsgBox working but shows second time after clicking OK

    Hello,
    This is my first post to this forum, so I apologize in advance if I am in the wrong place. I am having a problem with a MsgBox (Excel 2010) that I'm hoping to get help with. The message box appears as expected, except when I click OK, it shows a second time. Clicking OK the second time then brings me back to cell C11. What I am trying to do is force the user to enter data into C11. If they click in C11 and do not enter anything, I want a message box to display asking them to enter the value. I'm not sure what I am doing wrong, and am also wondering if there is a better way of doing this.
    Here is my code.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Sheets("Info").Range("C11").Value = “” Then
    
        MsgBox "Please provide your name"
        
      Cancel = True
      
      Range("C11").Select
    
      Cancel = True
    
    End If
    End Sub
    Thanks in advance!

  2. #2
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: MsgBox working but shows second time after clicking OK

    Hi Stella,

    Add the following code before your "If" statement:

    application.enableevents = false
    Add this code following the "End If" Statement:

    application.enableevents = true
    I think that should work. It looks like the routine is actually running twice as on the first run, it enables a second event. If you shut off "Enable Events" it should keep that from happening.

    Thanks,

    Daniel

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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