ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm and .hide: prevent code from further execution (https://www.excelbanter.com/excel-programming/389101-userform-hide-prevent-code-further-execution.html)

Christian[_9_]

UserForm and .hide: prevent code from further execution
 
Hi,

I can show a Userform by "SampleUserForm.Show" and make it dissapear
by "SampleUserForm.hide"
So far, so good.

I created code which might produce a division by zero, depending on
former input. My code (simplified UserForm):


Private Sub Calculation

If a <= 0 Then
Calculation.Hide ' Just this UserForm should "hide"/disappear
and code in just this Userform should stop
End If

b = Log (a) ' This leads to an error (division by zero)
if a <= 0

End Sub


So ".Hide" makes the UserForm disappear but keeps the code running.
Otherwise "Stop" (or is it "Halt"?) would make the whole program stop.
I'm searching for a possibility to hide the UserForm and prevent the
code in this UserForm from going on.

Thanx for any suggestions,

- Christian


Norman Jones

UserForm and .hide: prevent code from further execution
 
Hi Christian,

Try something like:

'=============
Private Sub CommandButton1_Click()
Dim a As Double
Dim b As Double

If a <= 0 Then
Unload Me
Exit Sub
End If
b = Log(a)
End Sub
'<<============


---
Regards,
Norman


"Christian" wrote in message
oups.com...
Hi,

I can show a Userform by "SampleUserForm.Show" and make it dissapear
by "SampleUserForm.hide"
So far, so good.

I created code which might produce a division by zero, depending on
former input. My code (simplified UserForm):


Private Sub Calculation

If a <= 0 Then
Calculation.Hide ' Just this UserForm should "hide"/disappear
and code in just this Userform should stop
End If

b = Log (a) ' This leads to an error (division by zero)
if a <= 0

End Sub


So ".Hide" makes the UserForm disappear but keeps the code running.
Otherwise "Stop" (or is it "Halt"?) would make the whole program stop.
I'm searching for a possibility to hide the UserForm and prevent the
code in this UserForm from going on.

Thanx for any suggestions,

- Christian




Christian[_9_]

UserForm and .hide: prevent code from further execution
 
On 10 Mai, 12:19, "Norman Jones"
wrote:
Hi Christian,

Try something like:

'=============
Private Sub CommandButton1_Click()
Dim a As Double
Dim b As Double

If a <= 0 Then
Unload Me
Exit Sub
End If
b = Log(a)
End Sub
'<<============

---
Regards,
Norman

"Christian" wrote in message

oups.com...

Hi,


I can show a Userform by "SampleUserForm.Show" and make it dissapear
by "SampleUserForm.hide"
So far, so good.


I created code which might produce a division by zero, depending on
former input. My code (simplified UserForm):


Private Sub Calculation


If a <= 0 Then
Calculation.Hide ' Just this UserForm should "hide"/disappear
and code in just this Userform should stop
End If


b = Log (a) ' This leads to an error (division by zero)
if a <= 0


End Sub


So ".Hide" makes the UserForm disappear but keeps the code running.
Otherwise "Stop" (or is it "Halt"?) would make the whole program stop.
I'm searching for a possibility to hide the UserForm and prevent the
code in this UserForm from going on.


Thanx for any suggestions,


- Christian




Thank you very much, that's it!



All times are GMT +1. The time now is 01:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com