We help IT Professionals succeed at work.
Get Started

Excel UserForm.Show "Code execution has been interruped" error

Last Modified: 2015-07-13
I have a button on a worksheet that when clicked executes:
Private Sub cmdGetQuote_Click()
End Sub

Open in new window

The first time the button is clicked, the user form shows.  I have a listbox come up and they click the item they want, then click the OK button, which goes through the list box and returns the selected value to the current worksheet.
Private Sub cmdOK_Click()
    On Error GoTo ErrHandler
    Dim lngItem As Long
    Dim I As Long
    Dim msg As String
    If ListBox1.ListIndex <> -1 Then
        For I = 0 To ListBox1.ColumnCount - 1
            msg = msg & ListBox1.Column(I) & vbCrLf
        Next I
    End If

    For lngItem = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(lngItem) Then
            With Sheets("Sheet1") '< qualify sheet here
                .Range("B2").Value = ListBox1.List(lngItem, 0)
            End With
        End If
    Next lngItem
    Unload Me
  Unload Me
  Exit Sub
  MsgBox "Error: " & Err.Number & " " & Err.Description & " :ListBox1_DblClick"
  GoTo ExitHandler
End Sub

Open in new window

I am then back at Sheet1 and see my value in cell B2.  Then the problem occurs.  I click on the button to show the form again and I get the Microsoft Visual Basic Error dialog box with the error:
Code execution has been interruped

If I click continue, everything is fine.  
Why am I getting this?
How do I prevent this from happening?
Watch Question
Consultant (Development Team Lead, Senior Support Engineer, and Technical Test Leader)
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE