Home Using a variable in 2 subs

# Using a variable in 2 subs

Bildircin13
1#
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 ThisWorkbook.Worksheets("Storyboard").Delete Yeni_Sheet_Adi_Olustur.Hide 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 ThisWorkbook.Worksheets("Storyboard").Delete 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
2#
 The UserForm .Tag property can be set to something on the button click events: Private Sub buttonOK_Click() Me.Tag = "OK" Me.Hide End Sub Private Sub buttonCancel_Click() Me.Tag = "Cancel" Me.Hide End Sub  and then check it's value after showing the form: UserForm1.Show MsgBox UserForm1.Tag <> "OK"