Declaring Public values in userform

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Hello all,

I haven't really used much in the way of public variables before, so I seem to be doing something wrong. In my userform, I have declared:
Code:
Public closeResend As String
at the very top.

Now I have this:
Code:
closeResend = "Yes"
as one of the commandbutton click functions.

In my module (where the userform originated) I have this:
Code:
If closeResend = "Yes" Then  
  Exit Sub
End If

Basically, I wanted to declare some sort of value when a button was clicked and then have my code check the value to exit the sub instead of continuing to run.

any help would be greatly appreciated.
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Where exactly is the 2nd code located?
 
Upvote 0
This is the code in my userform:

Code:
Public closeResend As String



Private Sub CommandButton1_Click()
Me.Hide
Application.ScreenUpdating = False
Sheets("Scheduler").Range("AH1").ClearContents
Sheets("Initial").Visible = True
Sheets("Initial").Select
closeResend = "Yes"
End Sub


Private Sub CommandButton2_Click()
Me.Hide
Application.ScreenUpdating = False
closeResend = "Yes"
End Sub


Private Sub Label1_Click()


End Sub


Private Sub UserForm_Click()


End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)


        If CloseMode = 0 Then Cancel = True


End Sub
 
Upvote 0
Place your public variable at top of a standard module.

Dave
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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
Back
Top