end sub in If then macor

  • Thread starter Thread starter P. Blaauw
  • Start date Start date
P

P. Blaauw

If I want to end the sub routine "Private Sub
UserForm_Initialize()" in a if then command, what will be
the command for that. I tried end Sub and Exit Sub but
that doesn't seem to work
 
Try this example that don't run the code if cell A1 have a value of 1

Private Sub UserForm_Initialize()
If Sheets("sheet1").Range("a1").Value = 1 Then Exit Sub
MsgBox "hi"
End Sub
 
Hi,



It seems that you don't wand the form to show. If it's the case, exit sub
will jus get you out of the initialize procedure and keep display the form.
As the name said, it is use to give initial values to something. To remove
the form, use a code like that:



If MsgBox("ok", vbYesNo) = vbYes Then Unload Me



And in the procedure that display the form, trap the error because it will
try to display some thing that is not in memory.



On Error Resume Next

UserForm1.Show
 
Back
Top