Home Using a variable in 2 subs
Reply: 1

Using a variable in 2 subs

Bildircin13 Published in 2017-09-12 11:25:42Z

I have over 20 subs in an excel file, and some userforms. In one userform, there is a cancel button, but I cannot use the "if cancel = true" kinda code in another sub. I don't know why, but it never comes true. So I thought that if I can state a variable to be true in userform, then check that variable in another sub, then that may work but unfortunately I couldn't figure that either. In below you can find both codes;

This is userform;

Private Sub Sheet_Iptal_Click()
Dim Sheet_Iptal As String
Sheet_Iptal = True
MsgBox "Islem iptal edildi."
Yeni_Sheet_Adi_Olustur.Yeni_Sheet.Value = ""
End Sub

And here is the part of the other sub where I want to check that "Sheet_Iptal" situation;

If Sheet_Iptal = True Then
    GoTo son
End If

What I am basically trying to achieve in here is, if cancel button has been used, then go to "son" of that specific sub. I am open to any suggestions here.

Slai Reply to 2017-09-13 12:36:39Z

The UserForm .Tag property can be set to something on the button click events:

Private Sub buttonOK_Click()
    Me.Tag = "OK"
End Sub

Private Sub buttonCancel_Click()
    Me.Tag = "Cancel"
End Sub

and then check it's value after showing the form:

MsgBox UserForm1.Tag <> "OK"
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.52887 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO