UserForm hangs on error check

LwarenceD

New Member
Joined
Nov 24, 2005
Messages
29
Here's one thats got me bugged,

If the error check finds nothing in textbox12 of the userform1, it reports the error correctly.

Entering the info into textbox12 AFTER the check triggers, the code stops and the workbook hangs, the only way to clear is to close the UserForm and begin again.

If I remove the first Exit Sub the error check does not trap.

Any Suggestions?

Code:
Private Sub CommandButton1_Click()

   If Not IsNumeric([TextBox12].Value) Or [TextBox12].Value < 1 Then _
        MsgBox "Number of Lines not defined or less than zero.", , _
               "Try Again":
              'Range("TextBox12").Select
        Exit Sub


ActiveWorkbook.Sheets("Remarks").Activate

Range("A1:A11").ClearContents
Range("A1") = TextBox1.Text
Range("A2") = TextBox2.Text
Range("A3") = TextBox3.Text
Range("A4") = TextBox4.Text
Range("A5") = TextBox5.Text
Range("A6") = TextBox6.Text
Range("A7") = TextBox7.Text
Range("A8") = TextBox8.Text
Range("A9") = TextBox9.Text
Range("A10") = TextBox10.Text
Range("A11") = TextBox11.Text

Unload UserForm1

Sheets("Main Menu").Select

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi

Try changing it to

Code:
Private Sub CommandButton1_Click() 

   If Not IsNumeric([TextBox12].Value) Or [TextBox12].Value < 1 Then _ 
        MsgBox "Number of Lines not defined or less than zero.", , _ 
               "Try Again" 
              TextBox12.setfocus
        Exit Sub 
  end if


ActiveWorkbook.Sheets("Remarks").Activate 

Range("A1:A11").ClearContents 
Range("A1") = TextBox1.Text 
Range("A2") = TextBox2.Text 
Range("A3") = TextBox3.Text 
Range("A4") = TextBox4.Text 
Range("A5") = TextBox5.Text 
Range("A6") = TextBox6.Text 
Range("A7") = TextBox7.Text 
Range("A8") = TextBox8.Text 
Range("A9") = TextBox9.Text 
Range("A10") = TextBox10.Text 
Range("A11") = TextBox11.Text 

Unload UserForm1 

Sheets("Main Menu").Select 

End Sub


Tony
 
Upvote 0
Returns the Compile error

"End If without Block If"

It was one of the first thing I tried.

Only thing I can think of is the logic flow is out of whack. But I've stared at it for too long and cant see it =P

Thanks for the reply tho.. =)
 
Upvote 0
You have your If statement followed by _ which continues the If statement in one line of code.

Code:
Private Sub CommandButton1_Click()

   If Not IsNumeric([TextBox12].Value) Or [TextBox12].Value < 1 Then 
        MsgBox "Number of Lines not defined or less than zero.", , _
               "Try Again"
              TextBox12.setfocus
        Exit Sub
  end if 
.....rest of code
 
Upvote 0
Thanks guys..

My eyes were WAY too close to the screen.. I missed the

TextBox12.setfocus

Its now working..


Thanks again

Cheers
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,141
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top