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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
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
 

LwarenceD

New Member
Joined
Nov 24, 2005
Messages
29
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.. =)
 

XLGibbs

Well-known Member
Joined
Feb 25, 2005
Messages
2,446
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
 

LwarenceD

New Member
Joined
Nov 24, 2005
Messages
29
Thanks guys..

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

TextBox12.setfocus

Its now working..


Thanks again

Cheers
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,998
Messages
5,834,802
Members
430,322
Latest member
excelnoobnoob

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
Top