Passing variables between procedures

cs1ctp

Board Regular
Joined
Oct 7, 2005
Messages
122
Hi,

I have a series of buttons that when clicked, open the same user form. There is a link label on the user form that when clicked displays a particular tab in the spreadsheet depending on the button that was pressed. The code for the buttons is in Sheet1(Code), the Code for the user form is in UserForm1(Code). Basically I would like to know how I can set a variable when a button is clicked and then pass this to the UserForm1(Code) so that when the link is clicked the correct tab is opened on the spreadsheet dependent on the button that was pressed.

This is the Sub attached to the button
Code:
Private Sub CommandButton1_Click()
variable = 1
End Sub

Code:
Private Sub CommandButton2_Click()
variable = 2
End Sub

Then in a seperate location this is the Sub for the label.
Code:
Private Sub Label5_Click()
If variable = 1 Then ...
Else 
If variable = 2 Then ...
End If
End Sub

What is the code for passing a variable between these two procedures?

Many thanks in advance for your help,

Chris
 
Chris

What I'm suggesting is 1 button on the spreadsheet to open the userform.

Then buttons(or other controls) on the form that goto the various locations.

For the public variable, have you tried declaring it in a standard module (Insert>Module) like I suggested?
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,225,071
Messages
6,182,682
Members
453,132
Latest member
nsnodgrass73

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