code in userforms

bharnett

Board Regular
Joined
Aug 5, 2004
Messages
94
Probably a dumb question, but I'm starting to have a lot of code for 2 userforms and it seems that excel will not let me have code in other modules that are specific to the values/variable assocatied and stored within the userform. For example, I have my intiliazation code in the userform code, but if cmdbutton block of code, I can't have that call code that is in another module, i have to put it in userform too. It is just getting cluttered and I wanted to know if there is a better or easier way to Organize my data. Thanks.

:biggrin: :LOL: :biggrin: :LOL:
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
It is really only necessary to have code in a Userform code module that deals with its events. Rather like a worksheet code module. This can run subroutines in other modules.

This code shows 2 methods of sharing variables between modules.

1. Declare variables top of module as Public - makes them available to all modules in all MS Office applications

2. Userforms retain their values until unloaded, so it is often useful to include code to Hide (or Show) the form eg. included in a button_click routine.

Code:
'- in a standard code module
Public MyString As String

Sub test()
    MyString = UserForm1.TextBox1.Value
    MsgBox (MyString)
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,356
Members
449,155
Latest member
ravioli44

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